The Android layout is divided into five main categories: relative layout, linear layout, table layout, frame layout, grid layout
Relative layout
Syntax format:
<relativelayout
Xmlns:android= "Http://schemas.android.com/apk/res/android"
Xmls:tools= "" Http://schemas.android.com/tools
Android:layout_width= ""
Android:layout_height= "" >
<Widgets>
Android:id= "@+id/"
Android:layout_width= "Wrap_content"
android:layout_height= "Wrap_content"
Android:layout_centerhorizontal= ""
Android:layout_alignparentleft= ""
Android:layout_marginleft= ""
</Widgets>
</RelativeLayout>
Syntax properties relative to the parent container layout
Property Name Property Description
Layout_alignparentleft the left edge of the parent container as the reference standard
Layout_marginleft the distance of the left edge of the control from the left edge of the parent container
Layout_alignparentrigth with the edge of the parent container as the reference standard
Layout_marginright the distance from the right edge of the control to the right edge of the parent container
Layout_alignparenttop the top edge of the parent container as the reference standard
Layout_margintop the distance of the top edge of the control from the top edge of the parent container
Layout_alignparentbottom the lower edge of the parent container as the reference standard
Layout_marginbottom the distance of the lower edge of the control from the lower edge of the parent container
Layout_centerhorizontal controls are centered horizontally in the parent container
Layout_centerhorizontal controls are centered vertically in the parent container
Layout_centerinparent control in the center of the parent container
Example:
<?xml version= "1.0" encoding= "Utf-8"?>
<relativelayout xmlns:android= "Http://schemas.android.com/apk/res/android"
android:layout_width= "Match_parent"
android:layout_height= "Match_parent" >
<button
android:id= "@+id/btn1"
android:layout_width= "Wrap_content"
android:layout_height= "Wrap_content"
android:layout_alignparenttop= "true"
android:layout_margintop= "128DP"
android:layout_centerhorizontal= "true"
android:text= "Button1"/>
</RelativeLayout>
Syntax properties for relative control layout
Property name Property Description
Layout_alignleft the left edge of a known control as the reference standard
The distance between the left edge of the Layout_marginleft control and the known control
Layout_alignright the right edge of a known control as the reference standard
the distance between the right edge of the Layout_marginright control and the known control
Layout_aligntop the top edge of a known control as a reference standard
The distance between the top edge of the Layout_margintop control and the known control
Layout_alignbottom the lower edge of a known control as a reference standard
Layout_marginbottom the distance between the bottom edge of the control and the known control
Layout_alignbaseline reference standard with baseline of known controls
Layout_torightof control on the right side of a known control
Layout_toleftof control on the left side of a known control
The Layout_above control is located on the top side of a known control
Layout_below control on the lower side of a known control
Example
<?xml version= "1.0" encoding= "Utf-8"?>
<relativelayout xmlns:android= "Http://schemas.android.com/apk/res/android"
android:layout_width= "match_parent" android:layout_height= "match_parent" >
<button
android:id= "@+id/btn1"
android:layout_width= "Wrap_content"
android:layout_height= "Wrap_content"
android:layout_centerinparent= "true"
android:text= "Button1"/>
<button
android:id= "@+id/btn2"
android:layout_width= "Wrap_content"
android:layout_height= "Wrap_content"
android:layout_alignbottom= "@+id/btn1"
android:layout_marginbottom= "85DP "
android:layout_torightof= "@+id/btn1"
android:text= "Button2"/>
</RelativeLayout>
Android layout---relative layout