如何使用RelativeLayout
在Android
中获得此布局?无论我尝试什么,前2个按钮都不会按预期显示。下面我提供了我想要的东西,我尝试的东西以及我的尝试输出的截图。请任何人都可以帮助我?谢谢。如何在Android中实现这种布局?
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#f5f5f5"
tools:context=".MainActivity" >
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:text="Button" />
<Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:text="Button" />
<Button
android:id="@+id/button3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:text="Button" />
<Button
android:id="@+id/button4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@+id/button3"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_below="@+id/button1"
android:text="Button" />
</RelativeLayout>
更新时间:
任何帮助深表感谢。
为什么使用'RelativeLayout'?你可以很容易地用一个外部垂直'LinearLayout'来实现,这个'LinearLayout'包含一个用于按钮1和2的水平'LinearLayout',然后是按钮3和按钮4.只需将'layout_weight'设置为水平LinearLayout的1/8/1;按钮3/4分别。 – Squonk 2015-02-24 15:27:40