Relative layout: relativelayout
Relativelayout is also a very common layout that allows you to precisely align the position of the control, set the relative position of the control with other controls, and the position of the control in the container. The default control position is the topmost and leftmost. The following is an example of how to interpret.
<?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= "Wrap_content" > <!--Test: Settings wrap_content also occupy full screen or fill parent-
<!--the first control: Place the username TextView at the top, which is actually the default location, testing only the property syntax--
<textview android:id= "@+id/usernamelb1"
Android:layout_width= "Wrap_content"
android:layout_height= "Wrap_content"
android:layout_alignparenttop= "true"
android:text= "UserName:"/>
<!--the second control: Place the EditText on the right side of the first control, the top and bottom position, default to the most
<edittext android:id= "@+id/usernametext"
Android:layout_width= "Match_parent"
android:layout_height= "Wrap_content"
android:layout_torightof= "@id/usernamelb1"/>
<!--the third control: since EditText occupies a greater height than TextView, the third control, which we put under the second control, is placed by default on the left-to-
<textview android:id= "@+id/pwdlb1"
Android:layout_width= "Wrap_content"
android:layout_height= "Wrap_content"
android:layout_below= "@id/usernametext"
android:text= "Password:"/>
<!--Fourth control: placed under the second control, and to the right of the third control. If we only set the position to the right of the third control, we find that the control overlaps with the second control because the control is placed at the top---
<edittext android:id= "@+id/pwdtext"
Android:layout_width= "Match_parent"
android:layout_height= "Wrap_content"
android:layout_alignleft= "@+id/usernametext"
android:layout_below= "@id/usernametext"/>
<!--test: The relative position of the control in other controls--
<textview android:id= "@+id/pwdcriteria"
Android:layout_width= "Match_parent"
android:layout_height= "Wrap_content"
android:layout_below= "@id/pwdtext"
android:text= "Password Criteria ..."/>
<!--test: The relative position of the control in the container--
<textview android:id= "@+id/disclaimerlb1"
Android:layout_width= "Match_parent"
android:layout_height= "Wrap_content"
android:layout_alignparentbottom= "true"
android:text= "Use at your own risk ... At your peril "/>
</RelativeLayout>
Reciprocal position Calibration
In the example, we find that because the height of TextView and EditView is different, we want to lower the position of the textview slightly, the bottom datum and EditView are the same.
What's special here is that we want the third control to be aligned with the fourth control, which is the fourth control we have not yet described, so we need to first add the ID of the fourth control to the R.java in the @+id/way. Because the ID value of the fourth control is already described earlier, it is possible to use @id/, but here we can still use @+id/, because the meaning of the + is that if it does not exist then it is incremented, if it exists.
Using the ADT View tool
In, we find that two edittext are not aligned because the text length of the first control "UserName:" and the Second control "Password:" is different. In the layout, we can see the alignment through the ADT View tool, and we can also make adjustments directly using the ADT View tool.
Adjust the control's extrude with the mouse, examine the XML file, and for the fourth control, add the Android:laytou_alignleft property.
<edittext android:id= "@id/pwdtext"
Android:layout_width= "Match_parent"
android:layout_height= "Wrap_content"
android:layout_alignleft= "@+id/usernametext"
android:layout_below= "@id/usernametext"/>
RELATED Links: My Android development related articles
"Turn" Pro Android Learning Note (26): User interface and Control (+): relativelayout