2012-03-02 9 views
0

私の人生にとって、私のボックスを水平と垂直の両方に集中させる方法を理解できません。センターこのAndroidレイアウト?

Download Google Chrome to see this image. http://img196.imageshack.us/img196/3593/stupidlayout.png

HERESに私のxml:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:background="@drawable/dragon" 
    android:orientation="vertical" > 

    <LinearLayout 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_gravity="center" 
     android:background="@drawable/playerinfosquare" 
     android:orientation="vertical"> 

     <TextView 
      android:id="@+id/spellinfotitle" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_gravity="center_horizontal" 
      android:layout_margin="10px" 
      android:text="Spellventory" 
      android:textAppearance="?android:attr/textAppearanceLarge" /> 

     <TextView 
      android:id="@+id/spell1info" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_gravity="center_horizontal" 
      android:layout_margin="10px" 
      android:text="No Spell Equipped" 
      android:textAppearance="?android:attr/textAppearanceMedium" /> 

     <TextView 
      android:id="@+id/spell2info" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_gravity="center_horizontal" 
      android:layout_margin="10px" 
      android:text="No Spell Equipped" 
      android:textAppearance="?android:attr/textAppearanceMedium" /> 

     <TextView 
      android:id="@+id/spell3info" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_gravity="center_horizontal" 
      android:layout_margin="10px" 
      android:text="No Spell Equipped" 
      android:textAppearance="?android:attr/textAppearanceMedium" /> 

    </LinearLayout> 

</LinearLayout> 

ヘルプ?

あなたは私を冗談ですか?スタックオーバーフローは、それが私より優れていると思って、自分のコードセクションを説明するのに十分な内容がないと言います。まあ、ここに行く!これは、常に意味をなさない任意のルールを持つために得られるものです。

+0

このルールは、多くのコードのみが尋ねられるところで重要な種類です。いいよ! :D – WarrenFaith

答えて

3

2番目のLinearLayoutをRelativeLayoutに配置します。その後、第二のLinearLayoutあなたはあなたの最初のLinearLayoutにandroid:gravity="center"を設定する必要が

+0

ちょうど私が必要なもの、ありがとう。 – Ring

1

android:layout_centerInParent="true" 

を設定することで、それははるかに簡単にセンタリングすることができます。

関連する問題