2012-03-02 50 views
0

我不能爲我的生活弄清楚如何讓我的箱子在水平和垂直方向上居中。居中此Android佈局?

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

繼承人我的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 2012-03-02 00:48:56

回答

3

把你的第二個LinearLayout放到一個RelativeLayout中。然後,您可以居中它更通過在第二的LinearLayout

+0

正是我所需要的,謝謝。 – Ring 2012-03-02 00:49:45

1

您需要設置android:gravity="center"你的第一個的LinearLayout設置

android:layout_centerInParent="true" 

容易。