The relative layout should be more flexible than the linear layout and table layout, so it is usually used more often. Relative to the position of the layout control is relative to the position of the control around it, as you can see from the name, these positions are relatively, determining the position of one of the controls to determine the position of the other control.
This experiment is to show the following activity:
Only 2 of them button,1 a textview,1 edittext.
In a relative layout, the control properties that are generally used are interpreted as follows:
The following properties are available in the relative layout, as explained below:
Android:layout_above to place the bottom of the control above the specified ID control
Android:layout_below Similarly, place the top of the control below the specified ID control
Android:layout_toleftof places the right side of the control next to the left end of the specified ID control.
Android:layout_torightof Place the left end of the control next to the right end of the specified ID control
Aligns the right end of the control with the right end of the parent control when Android:layout_alignparentright is True
Android:layout_alignparentleft the control left to the parent control left when True
Aligns the top of the control to the top of the parent control when Android:layout_alignparenttop is True
Aligns the bottom of the control with the bottom of the parent control when Android:layout_alignparentbottom is True
Android:layout_alignbottom aligns the bottom of the control with the control at the bottom of the specified ID control
Android:layout_alignleft aligns the control to the left of the specified ID control
Android:layout_alignright aligns the control to the right of the specified ID control
Android:layout_aligntop aligns the top of the control to the top of the specified ID control
Implementing the above activity is simpler, with the following XML code:
Copy Code code as follows:
<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:padding= "10px" >
<textview
Android:id= "@+id/input"
Android:layout_width= "Fill_parent"
android:layout_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= "@android:d rawable/editbox_background"
/>
<button
Android:id= "@+id/ok"
android:layout_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>
Summary: The relative layout of the activity is more flexible, some common properties are more, the use of a lot of natural will be.
Author: tornadomeet