案例效果:
源码:
<RelativeLayout android:layout_height="wrap_content"
xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="wrap_content"
>
<TextView
android:id="@+id/labe1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="相对布局"
android:textSize="50sp">
</TextView>
<EditText
android:id="@+id/et1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/labe1">
</EditText>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/et1"
android:text="OK"
android:layout_alignParentRight="true"
android:layout_marginRight="10dp"></Button>
</RelativeLayout>
两个值true对齐,false不对齐
相对某个控件layout_toLeftOfs (例子中没写)
总结:相对布局比较简单,主要注意每个控件取个id名即可