Android RelativeLayout Tutorial

Relative Layout

RelativeLayout is a view group that displays child views in relative positions. The position of each view can be specified as relative to sibling elements (such as to the left-of or below another view) or in positions relative to the parent RelativeLayout area (such as aligned to aligned to the bottom, left or center).

Note: For more Complex layout you should use the constraintlayout
Relative layout is a very powerful Utility tool for designing the complex layout it can eliminate the nested few groups and keep your hierarchy flat. You can use a single relative layout instead of more complex linearlayout.

Positioning the views

Now let's talk about how you cannot position your views in the layout .In layout positioning of the each view related to an another view or the parent layout. Unlike linearlayout you have to give each view and special attribute to determine their position.

XML Attributes


I will not discuss all of the attributes properties of the relative layout but I will need to discuss some important properties or attributes the to this post let's see what they are-

Some of the layout properties available in the relative layout are


android:layout_alignParentTop
If "true", makes the top edge of this view match the top edge of the parent.


android:layout_centerVertical
If "true", centers this child vertically within its parent.

android:layout_below
Positions the top edge of this view below the view specified with a resource ID.


android:layout_toRightOf
Positions the left edge of this view to the right of the view specified with a resource ID.

The value of these properties should be a Boolean value aur ID of a view.


Post a Comment

0 Comments