The relative layout is more flexible than the linear layout and table layout, so it is usually used more often. The position of the relative layout control is related to the position of the control around it, as you can see from the name, the positions are relative, and the position of one of the controls is determined to determine the position of the other control.
This experiment shows the following activity:
Only 2 of them button,1 textview,1 EditText.
The implementation of the above activity is relatively simple, the XML code is as follows:
<span style= "Font-family:comic Sans ms;font-size:18px;" ><relativelayout xmlns: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 "Android:paddi ng= "10px" > <textview android:id= "@+id/input" android:layout_width= "Fill_parent" Android:lay out_height= "Wrap_content" android:text= "@string/input_dis" tools:context= ". Mainactivity "/> <edittext android:id=" @+id/edit "android:layout_width=" Fill_parent " android:layout_height= "Wrap_content" android:layout_below= "@id/input" android:background= "@androi D:drawable/editbox_background "/> <button android:id=" @+id/ok "Android:layo ut_height= "Wrap_content" android:layout_width= "wrap_content" android:layout_below= "@id/edit" Android:layout_Alignparentright= "true" android:layout_marginleft= "10px" android:text= "@string/ok" /> <button android:id= "@+id/cancel" android:layout_height= "Wrap_content" Android:layout_width= "Wrap_content" android:layout_below= "@id/edit" android:layout_toleftof= "@id/ok "Android:text=" @string/cancel "/></relativelayout></span>
In the relative layout there are the following properties, which are explained as follows:
Relative to the given ID control
Android:layout_above the bottom of the control to the control of the given ID;
Android:layout_below Place the bottom of the control under the control of the given ID;
Android:layout_toleftof aligns the right edge of the control with the left edge of the control for the given ID;
Android:layout_torightof aligns the left edge of the control with the right edge of the control for the given ID;
Android:layout_alignbaseline aligns the baseline of the control with the baseline of the given ID;
Android:layout_aligntop aligns the top edge of the control with the top edge of the given ID;
Android:layout_alignbottom aligns the bottom edge of the control with the bottom edge of the given ID;
Android:layout_alignleft aligns the left edge of the control with the left edge of the given ID;
Android:layout_alignright aligns the right edge of the control with the right edge of the given ID;
Relative to Parent component
Android:layout_alignparenttop If true, aligns the top of the control with the top of its parent control;
Android:layout_alignparentbottom If true, aligns the bottom of the control with the bottom of its parent control;
Android:layout_alignparentleft If true, aligns the left part of the control with the left part of its parent control;
Android:layout_alignparentright If true, aligns the right part of the control with the right side of its parent control;
Center
Android:layout_centerhorizontal If True, the control is placed horizontally centered;
Android:layout_centervertical If True, the control is placed vertically centered;
Android:layout_centerinparent If True, the control is placed in the center of the parent control;
Specify moving pixels
The value of the offset on the android:layout_margintop;
Android:layout_marginbottom the value of the offset;
Android:layout_marginleft the value of the left offset;
Android:layout_marginright the value of the right offset;
Continued
android:layout_alignparentright= "true"
Aligns the right end of the current control with the right end of the parent control. This property value can only be true or FALSE, which is false by default.
android:layout_marginleft= "10dip"
leave the space on the left side of the current control empty.
android:layout_toleftof= "@id/ok"
places the current control to the left of the control with an OK ID.
android:layout_aligntop= "@id/ok"
aligns the current control with the upper end of the ID control.
padding indicates padding, margin indicates margin
can be set through the Android:padding property, with a margin property of 4 directions of Android:paddingleft, Android:paddingright, Android:paddingtop, and Android: Paddingbottom.
Conclusion:
*android:layout_marginbottom
*android:layout_marginleft
*android:layout_marginright
*android:layout_margintop
The values of the above properties are calculated based on the value of the object relative to the position below, and if no relative object is calculated as the overall layout
*android:layout_below
*android:layout_above
*android:layout_toleftof
*android:layout_torightof
*android:layout_aligntop
*android:layout_centerhrizontal//whether horizontal screen or vertical screen is supported
*android:layout_centervertical//This is based on the meaning of the Word: Center vertical
*android:layout_centerinparent//
android:layout_centerinparent= "true"//centered on parent object
android:layout_centerinparent= "false" ... Browser does not support multi-window display, meaning that all pages in a single window open, so as to avoid page layout control display problems
the relative position of the following relative to the parent
*android:layout_alignparentbottom
*android:layout_alignparentleft
*android:layout_alignparentright
*android:layout_alignparenttop
*android:layout_alignwithparentifmissing
The relative layout of activity is more flexible, some common properties are also more, use more naturally will.
Android Layout Manager-relative layout relativelayout