代码如下:
<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 代码中,我发现 View 将相对于另一个 View 垂直显示,而是它们彼此堆叠。这里出了什么问题?
最佳答案
在 LinearLayout 中,您的字段将垂直显示。但在RelativeLayout 中,您必须指定它们彼此的相对位置。因此,如果您将“RelativeLayout”替换为“LinearLayout”,则一切就绪。
关于java - 为什么我的 View 不是垂直设置的?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12501643/