RelativeLayout
<?xml version="1.0" encoding="utf-8" ?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" > <!-- 定义该组件位于父容器中间 --> <TextView android:id="@+id/view1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@drawable/leaf" android:layout_centerInParent="true"></TextView> <!-- 定义该组件位于view1组件的上方,与给出ID的左边界对其 --> <TextView android:id="@+id/view2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@drawable/leaf" android:layout_above="@id/view1" android:layout_alignLeft="@id/view1"></TextView> <!-- 定义该组件位于view1组件的下方,与给出ID的左边界对其 --> <TextView android:id="@+id/view3" android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@drawable/leaf" android:layout_below="@id/view1" android:layout_alignLeft="@id/view1"></TextView> <!-- 定义该组件位于view1组件的左边 ,与给出ID的上边界对其--> <TextView android:id="@+id/view4" android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@drawable/leaf" android:layout_toLeftOf="@id/view1" android:layout_alignTop="@id/view1"></TextView> <!-- 定义该组件位于view1组件的右边 ,与给出ID的上边界对其--> <TextView android:id="@+id/view5" android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@drawable/leaf" android:layout_toRightOf="@id/view1" android:layout_alignTop="@id/view1"></TextView> </RelativeLayout>
控件的位置总是相对于兄弟、父容器来决定---相对布局