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 the bottom, left or center).

Center relative to Parent

To place Views in the center relative to the parent, we can use the following attributes:

  • android:layout_centerHorizontal if true, centers this child horizontally within its parent.
  • android:layout_centerVertical if true, centers this child vertically within its parent.
  • android:layout_centerInParent if true, centers this child horizontally and vertically within its parent.

 

Align by Parent

These attributes are used to define child layout to any side of the parent view.

  • android:layout_alignParentTop if true, makes the top edge of this view match the top edge of the parent.
  • android:layout_alignParentBottom if true, makes the bottom edge of this view match the bottom edge of the parent.
  • android:layout_alignParentLeft if true, makes the left edge of this view match the left edge of the parent.
  • android:layout_alignParentRight if true, makes the right edge of this view match the right edge of the parent.
  • android:layout_alignParentBottom if true, makes the bottom edge of this view match the bottom edge of the parent.
  • android:layout_alignParentEnd if true, makes the end edge of this view match the end edge of the parent.