Relative Layout
The relative layout is used to arrange the child views in a proper order which
means arranging the child objects relative to each other.
RelativeLayout Attributes
Sr.No. Attribute & Description
1 android:id
This is the ID which uniquely identifies the layout.
2 android:gravity
This specifies how an object should position its content, on both the X
and Y axes. Possible values are top, bottom, left, right, center,
center_vertical, center_horizontal etc.
3 android:ignoreGravity
This indicates what view should not be affected by gravity.
4 android:layout_above
Positions the bottom edge of this view above the given anchor view ID and
must be a reference to another resource, in the form
"@[+][package:]type:name"
5 android:layout_alignBottom
Makes the bottom edge of this view match the bottom edge of the given
anchor view ID and must be a reference to another resource, in the form
"@[+][package:]type:name".
6 android:layout_alignLeft
Makes the left edge of this view match the left edge of the given anchor
view ID and must be a reference to another resource, in the form
"@[+][package:]type:name".
7 android:layout_alignParentBottom
If true, makes the bottom edge of this view match the bottom edge of the
parent. Must be a boolean value, either "true" or "false".
8 android:layout_alignParentEnd
If true, makes the end edge of this view match the end edge of the parent.
Must be a boolean value, either "true" or "false".
9 android:layout_alignParentLeft
If true, makes the left edge of this view match the left edge of the parent.
Must be a boolean value, either "true" or "false".
10 android:layout_alignParentRight
If true, makes the right edge of this view match the right edge of the
parent. Must be a boolean value, either "true" or "false".
11 android:layout_alignParentStart
If true, makes the start edge of this view match the start edge of the parent.
Must be a boolean value, either "true" or "false".
12 android:layout_alignParentTop
If true, makes the top edge of this view match the top edge of the parent.
Must be a boolean value, either "true" or "false".
13 android:layout_alignRight
Makes the right edge of this view match the right edge of the given anchor
view ID and must be a reference to another resource, in the form
"@[+][package:]type:name".
14 android:layout_alignStart
Makes the start edge of this view match the start edge of the given anchor
view ID and must be a reference to another resource, in the form
"@[+][package:]type:name".
15 android:layout_alignTop
Makes the top edge of this view match the top edge of the given anchor
view ID and must be a reference to another resource, in the form
"@[+][package:]type:name".
16 android:layout_below
Positions the top edge of this view below the given anchor view ID and
must be a reference to another resource, in the form
"@[+][package:]type:name".
17 android:layout_centerHorizontal
If true, centers this child horizontally within its parent. Must be a boolean
value, either "true" or "false".
18 android:layout_centerInParent
If true, centers this child horizontally and vertically within its parent. Must
be a boolean value, either "true" or "false".
19 android:layout_centerVertical
If true, centers this child vertically within its parent. Must be a boolean
value, either "true" or "false".
20 android:layout_toEndOf
Positions the start edge of this view to the end of the given anchor view ID
and must be a reference to another resource, in the form
"@[+][package:]type:name".
21 android:layout_toLeftOf
Positions the right edge of this view to the left of the given anchor view ID
and must be a reference to another resource, in the form
"@[+][package:]type:name".
22 android:layout_toRightOf
Positions the left edge of this view to the right of the given anchor view ID
and must be a reference to another resource, in the form
"@[+][package:]type:name".
23 android:layout_toStartOf
Positions the end edge of this view to the start of the given anchor view ID
and must be a reference to another resource, in the form
"@[+][package:]type:name".
e.g.
Padding: in Android is used to add a blank space between a view and its contents.
android:padding="11dp"
android:paddingLeft="11dp" …………..
Margins, on the other hand, are used to add a space between two different views. The
following illustration will help to clarify the difference between the two:
e.g.
android:layout_margin="222dp"
android:layout_marginLeft="222dp"………….