android_learners_hub
Relative
Layout in Android
Today we will study What is Relative Layout? and Why and Where we use Relative Layout?
What
is Relative Layout?
Relative Layout is one of the layout for designing user interface in Android. It replaces the use of nested Linear Layout, that means if we have to make a Layout in which views are shown in both orientations then, we can use Relative Layout instead of Nested Linear Layout. Hence, Relative Layout arrange the Views as according to the other views i.e why it is called Relative Layout.
Why
and Where we use Relative Layout?
Relative Layout is used in the place of nested Linear Layout because if we use nested Linear Layout we have to write long code. Hence, it is easy to use Relative Layout beside using lengthy code in Linear Layout.
Therefore , we use relative layout there where we want to get the desire layout with respect to the Views used in the View Group (Relative Layout).
Some of the attributes used in the Relative Layout are following:-
1. android:id :- As the name specifies that this describes the id of ViewGroup that is ID of our Relative Layout.
2.android:gravity :- It sets the position of the content , that where the content will lie . For example: that it will be at top, bottom, center_vertical , center_horizontal and etc.
3.android:layout_above :-This describes that, this view will be below of the view specify in the value of this attribute. The value of this attribute will be the Id of the View(ex. id of Button, TextView , EditText etc.).
4.android:layout_below :- When we use this attribute in any view than it describes that, this view(which have this attribute) will be in bottom of that view which is mentioned in the value of this attribute.
// To set the view on the End, Right, Start and Left.
5.android:layout_toEndOf
6.android:layout_toRightOf
7.android:layout_toStartOf
8.android:layout_toLeftOf
// To set the alignment to Top, Bottom, Left and Right
9.android:layout_alignParentTop="true"
10.android:layout_alignParentBottom="true"
11.android:layout_alignParentLeft="true"
12.android:layout_alignParentRight="true"
// To center your View in Relative Layout.
13.android:layout_centerHorizontal="true"(center from Horizontal)
14.android:layout_centerVertical="true"(center from Vertical)
15.android:layout_centerInParent="true"(your view will become centered from vertical and horizontal )
we will do practical work in Relative Layout in the next post , this was just a little Introduction to Relative Layout.
for any query feel free to comment.
๐๐
ReplyDelete๐๐ Great
ReplyDelete