Example:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView
android:id="@+id/label"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Type here:"/>
<EditText
android:id="@+id/entry"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@android:drawable/editbox_background"
android:layout_below="@id/label"/>
<Button
android:id="@+id/ok"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/entry"
android:layout_alignParentRight="true"
android:layout_marginLeft="10dip"
android:text="OK" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toLeftOf="@id/ok"
android:layout_alignTop="@id/ok"
android:text="Cancel" />
</RelativeLayout>
First:
android:layout_below="@id/label"/>
It indicates that the current control is placed under the control whose ID is label.
android:layout_alignParentRight="true"
Align the right end of the current control with the right end of the parent control. The attribute value can only be true or false. The default value is false.
android:layout_marginLeft="10dip"
To make the left side of the current control empty.
android:layout_toLeftOf="@id/ok"
Indicates that the current control is placed on the left side of the control whose ID is OK.
android:layout_alignTop="@id/ok"
Indicates alignment between the current control and the upper end of the ID control.
The relative layout mainly has the following attributes:
Attribute 1: the property value is true or false.
* Android: layout_centerhrizontal
* Android: layout_centervertical
* Android: layout_centerinparent
* Android: layout_alignparentbottom
* Android: layout_alignparentleft
* Android: layout_alignparentright
* Android: layout_alignparenttop
* Android: layout_alignwithparentifmissing
Attribute 2: the property value must be the reference name "@ ID/ID-name" of the ID"
* Android: layout_below
* Android: layout_abve
* Android: layout_toleftof
* Android: layout_torightof
* Android: layout_aligntop
Attribute 3: The attribute value is a specific pixel value, measured in dip and PX.
* Android: layout_marginbottom
* Android: layout_marginleft
* Android: layout_marginright
* Android: layout_margintop
XML example:
<? XML version = "1.0" encoding = "UTF-8"?>
<Relativelayout
Xmlns: Android = "http://schemas.android.com/apk/res/android"
Android: layout_width = "fill_parent"
Android: layout_height = "fill_parent">
<Analogclock
Android: Id = "@ + ID/aclock"
Android: layout_width = "wrap_content"
Android: layout_height = "wrap_content"
Android: layout_centerinparent = "true"/>
<Digitalclock
Android: Id = "@ + ID/dclock"
Android: layout_width = "wrap_content"
Android: layout_height = "wrap_content"
Android: layout_below = "@ ID/aclock"
Android: layout_alignleft = "@ ID/aclock"
Android: layout_marginleft = "40px"/>
<Textview
Android: layout_width = "wrap_content"
Android: layout_height = "wrap_content"
Android: text = "current time :"
Android: layout_toleftof = "@ ID/dclock"
Android: layout_aligntop = "@ ID/aclock"/>
</Relativelayout>