我不能为我的生活弄清楚如何让我的盒子在水平和垂直方向上居中。
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 :(得分:3)
将第二个LinearLayout放入RelativeLayout。然后,您可以通过设置
使其更容易居中android:layout_centerInParent="true"
在第二个LinearLayout
上答案 1 :(得分:1)
您需要在第一个LinearLayout上设置android:gravity="center"
。