为什么我的观点没有垂直设置?

时间:2012-09-19 19:35:11

标签: java android

以下是代码:

    <RelativeLayout
            android:id="@+id/top_lay2"
            android:layout_below="@id/top_lay1"
            android:layout_width="fill_parent"
            android:layout_marginTop="10dp"
            android:orientation="vertical"
            android:layout_height="wrap_content"
            android:background="@drawable/customrect">
<TextView
            android:layout_gravity="center"
            android:layout_width="fill_parent"
            android:layout_height="wrao_content"
            android:textColor="@color/white1"
            android:text="some text"
         />
<Button
            android:layout_gravity="center"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:text="click me"
    />

    </RelativeLayout>

从那个xml代码中,我除了视图将相对于另一个垂直显示,而是相互堆叠。这有什么不对?

3 个答案:

答案 0 :(得分:1)

在LinearLayout中,您的字段将垂直显示。但是在RelativeLayout中,您必须指定它们相对于彼此的位置。因此,如果您将“RelativeLayout”替换为“LinearLayout”,那么您已经完成了设置。

答案 1 :(得分:0)

RelativeLayout RelativeLayout需要描述其子女相对于彼此的位置。

如果您希望自动定位,请使用LinearLayout,其方向设置为垂直。

答案 2 :(得分:0)

orientation="vertical"使用RelativeLayout不支持{p> LinearLayout或定义TextViewButton之间的正确关系。

同时检查 http://developer.android.com/guide/topics/ui/layout/linear.html

相关问题