Some of the important attributes that relativelayout uses:
First Class: Property value is True or False
Android:layout_centerhrizontal Horizontal Center
Android:layout_centervertical Vertical Center
Android:layout_centerinparent is completely centered relative to the parent element
Android:layout_alignparentbottom snaps to the bottom edge of the parent element
Android:layout_alignparentleft snaps to the left edge of the parent element
Android:layout_alignparentright snaps to the right edge of the parent element
Android:layout_alignparenttop snaps to the top edge of the parent element
android:layout_alignwithparentifmissing if the corresponding sibling element cannot be found, then the parent element is the reference.
Second class: The attribute value must be the reference name of the id "@id/id-name"
Android:layout_below at the bottom of an element
Android:layout_above at the top of an element
Android:layout_toleftof on the left side of an element
Android:layout_torightof on the right side of an element
Android:layout_aligntop aligns the top edge of this element with the top edge of an element
Android:layout_alignleft aligns the left edge of this element with the left edge of an element
Android:layout_alignbottom aligns the bottom edge of this element with the bottom edge of an element
Android:layout_alignright aligns the right edge of this element with the right edge of an element
Class III: Attribute values are specific pixel values, such as 30dip,40px
Android:layout_marginbottom distance from the bottom edge of an element
Android:layout_marginleft distance from the left edge of an element
Android:layout_marginright distance from the right edge of an element
Android:layout_margintop distance from the top edge of an element
Sample code
<?XML version= "1.0" encoding= "Utf-8"?><Relativelayoutxmlns:android= "Http://schemas.android.com/apk/res/android"Xmlns:tools= "Http://schemas.android.com/tools"Android:layout_width= "Match_parent"Android:layout_height= "Match_parent"Tools:context=". Relativelayoutactivity "> <!--Alignparent Position Property relative to parent control - <RelativelayoutAndroid:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"Android:layout_alignparentbottom= "true"Android:id= "@+id/id1"> <ButtonAndroid:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"Android:background= "#23acaa"Android:text= "Button 1"/> </Relativelayout> <!--Alignparent Position property of a control with relative ID - <RelativelayoutAndroid:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"Android:layout_torightof= "@+id/id1"Android:layout_above= "@+id/id1"Android:id= "@+id/id2"> <ButtonAndroid:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"Android:background= "#23acaa"Android:text= "button 2"/> </Relativelayout> <!--alignparent margin definition spacing - <RelativelayoutAndroid:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"Android:layout_torightof= "@+id/id2"Android:layout_marginleft= "20DP"Android:layout_marginbottom= "20DP"Android:layout_above= "@+id/id2"> <ButtonAndroid:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"Android:background= "#23acaa"Android:text= "button 3"/> </Relativelayout> <!--alignparent Center Positioning Center - <RelativelayoutAndroid:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"Android:layout_centerhorizontal= "true"android:layout_centervertical= "true"Android:id= "@+id/id4"> <ButtonAndroid:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"Android:background= "#23acaa"Android:text= "button 4"/> </Relativelayout></Relativelayout>
Android Layout Relativelayout