Important Attributes for Positioning Views in the RelativeLayout
As we know, we need to define the position of child views or ViewGroups relative to each other element or relative to the parent. By default position is top-left, if someone forgets to specify the position of child views.
XML attributes | Description |
---|---|
layout_alignParentLeft | It is set “true” to match the left edge of view to the left edge of parent. |
layout_alignParentRight | It is set “true” to match the right edge of view to the right edge of the parent. |
layout_alignParentTop | It is set to “true” to match the top edge of the view to the top edge of the parent. |
layout_alignParentBottom | It is set to “true” to match the bottom edge of the view to the bottom edge of the parent. |
layout_alignLeft | It accepts another sibling view ID and Align the view to the left of the specified view ID. |
layout_alignRight | It accepts another sibling view ID and Align the view to the right of the specified view ID. |
layout_alignStart | It accepts another sibling view ID and Align the view to the start of the specified view ID. |
layout_alignEnd | It accepts another sibling view ID and Align the view to the end of the specified view ID. |
layout_centerInParent | When it is set to “true”, the view will be aligned to the center of parent. |
layout_centerHorizontal | When it is set to “true”, the view will be horizontally centre-aligned within its parent. |
layout_centerVertical | When it is set to “true”, the view will be vertically centre-aligned within its parent. |
layout_toLeftOf | It accepts another sibling view ID and places the view left of the specified view ID. |
layout_toRightOf | It accepts another sibling view ID and places the view right of the specified view ID. |
layout_toStartOf | It accepts another sibling view ID and places the view to start of the specified view ID. |
layout_toEndOf | It accepts another sibling view ID and places the view to end of the specified view ID. |
layout_above | It accepts another sibling view ID and places the view above the specified view ID. |
layout_below | It accepts another sibling view ID and places the view below the specified view ID. |
Android RelativeLayout in Kotlin
Android RelativeLayout is a ViewGroup subclass, used to specify the position of child View elements relative to each other like (A to the right of B) or relative to the parent (fixed to the top of the parent). Instead of using LinearLayout, we have to use RelativeLayout to design the user interface and keep our hierarchy flat because it improves the performance of the application.