2012-03-02 4 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

Поместите свой второй LinearLayout в RelativeLayout. Вы можете центрировать его гораздо проще, установив

android:layout_centerInParent="true" 

на втором LinearLayout

+0

Просто то, что мне нужно, спасибо. – Ring

1

Вы должны установить android:gravity="center" на первый LinearLayout.

Смежные вопросы