RelativeLayout allows child elements to specify their locations (by ID) relative to other elements or parent layout objects.
In this example, RelativeLayout is used to display three textviews. The second TextView (id/view3) occupies the middle part of the screen. We have discussed how to use LinearLayout, use the specified View weight to achieve the same effect. Android ApiDemos example resolution (143): Views-> Layouts-> LinearLayout-> 3. vertical (Padded)
In this example, RelativeLayout is used. Because other views need to be used as reference objects, all child views must define IDs. Other child views determine their relative positions by specifying the IDs of the reference objects.
<RelativeLayout xmlns: android = "http://schemas.android.com/apk/res/android"
Android: layout_width = "match_parent"
Android: layout_height = "match_parent">
<! -View1 goes on top->
<TextView
Android: id = "@ + id/view1 ″
Android: background = "@ drawable/red"
Android: layout_width = "match_parent"
Android: layout_height = "wrap_content"
Android: layout_alignParentTop = "true"
Android: text = "@ string/relative_layout_{top"/>
<! -View2 goes on the bottom->
<TextView
Android: id = "@ + id/view2 ″
Android: background = "@ drawable/green"
Android: layout_width = "match_parent"
Android: layout_height = "wrap_content"
Android: layout_alignParentBottom = "true"
Android: text = "@ string/relative_layout_1_bottom"/>
<! -View3 stretches betweeen view1 and view2->
<TextView
Android: id = "@ + id/view3 ″
Android: background = "@ drawable/yellow"
Android: layout_width = "match_parent"
Android: layout_height = "0dip"
Android: layout_above = "@ id/view2 ″
Android: layout_below = "@ id/view1 ″
Android: text = "@ string/relative_layout_centercenter"/>
</RelativeLayout>
TextView1 (id/view1) indicates that its layout_alignParentTop relative to the parent container RelativeLayout is True, so it is displayed on the top of the screen.
TextView2 (id/view2) indicates that its android: layout_alignParentBottom relative to RelativeLayout of the parent container is True, so it is displayed at the bottom of the screen.
TextView3 (id/view3) is set to 0, but android: layout_above and android: layout_below indicate the relative position between TextView1 and TextView2 (adjacent to the top and bottom of two textviews ), therefore, TextView3 occupies all the remaining intermediate parts.