RelativeLayout
The RelativeLayout enables you to specify how child views are positioned relative to each other.Consider the following main.xml file:android:layout_width=”fill_parent”
android:layout_height=”fill_parent”
xmlns:android=”http://schemas.android.com/apk/res/android”
>
RelativeLayout
android:layout_width=”wrap_content”
android:layout_height=”wrap_content”
android:text=”Comments”
android:layout_alignParentTop=”true”
android:layout_alignParentLeft=”true”
/>
android:layout_width=”fill_parent”
android:layout_height=”170px”
android:textSize=”18sp”
android:layout_alignLeft=”@+id/lblComments”
android:layout_below=”@+id/lblComments”
android:layout_centerHorizontal=”true”
/>
RelativeLayout
RelativeLayout
Notice that each view embedded within the RelativeLayout has attributes that enable it to alignwith another view. These attributes are as follows:
➤layout_alignParentTop
➤ layout_alignParentLeft
➤ layout_alignLeft
➤ layout_alignRight
➤ layout_below
➤ layout_centerHorizontal
The value for each of these attributes is the ID for the view that you are referencing. The preceding
XML UI creates the screen shown in Figure.