Activity layout Preliminary-relative layout
1. The basic concept of relative layout
The position of a control it depends on its relationship with other controls, benefits: more flexible; Disadvantages: Mastery is more complicated.
2, relative layout commonly used property introduction
These attributes are divided into 4 groups for easy comprehension and memory.
A), the following 4 properties set the relationship and position between the control and
However, the above 4 properties do not set the alignment between controls.
Example 1: Placing control A above control B, using the Android:layout_above property, the effect of the control layout can be in either of the following cases.
1, control A is aligned with control B, and control A is above control B.
2. Control A is not aligned with control B, but control A is indeed above control B.
b), the following 5 properties, set the way the control aligns with the control (top, bottom, left, right).
Example 2: On the basis of Example 1, set control A to be placed above control B, use the Android:layout_above property, and the left edge of control a aligns with the left edge of control B, using the Android:layout_alignleft property.
c), the following 4 properties set how the control aligns with the parent control (top, bottom, left, right).
D), the following 4 properties set the direction of the control.
You can combine these properties to achieve a variety of layouts.
Note: The above properties and other properties can be found in the Android Help document;
Example 3: If you want to implement a program such as this layout
If such a layout is to use LinearLayout, it will be more cumbersome and complex,
1, first need a vertical layout direction of the LinearLayout, wrapping all the controls;
2, and then in the first linearlayout nested a vertical direction of the linearlayout, placed in the upper part, in this linearlayout into a textview and edittext;
3, finally in the first linearlayout nested a horizontal direction of the linearlayout, placed in the next part of the first linearlayout, put two buttons in this linearlayout, and also let them in the right.
Refer to:
If using relativelayout would be a lot easier, here is the code for Main.xml.
XML code <?xml version= "1.0" encoding= "Utf-8"?> <relativelayout xmlns:android= "http://schemas.android . Com/apk/res/android "android:layout_width=" fill_parent "android:layout_height=" Wrap_content "a ndroid:padding= "10px" > <textview android:id= "@+id/lable" android:text= " Type here: "Android:layout_width=" Fill_parent "android:layout_height=" Wrap_content "/&G T <edittext android:id= "@+id/entry" android:layout_width= "Fill_parent" Android:lay out_height= "Wrap_content" android:background= "@android:d rawable/editbox_background" Android:layo ut_below= "@id/lable"/> <button android:id= "@+id/ok" android:l Ayout_width= "Wrap_content" android:layout_height= "wrap_content" android:text= "OK" a ndroid:layout_below= "@id/entry" android:layout_marginleft= "10px" android:layout_alignparentright= " True "/> <button android:id=" @+id/cancel "android:layout_width = "Wrap_content" android:layout_height= "wrap_content" android:layout_toleftof= "@id/ok" android:layout_aligntop= "@id/ok" android:text= "Cancel"/> </RelativeLayout>
Transferred from: http://www.cnblogs.com/yyyyy5101/archive/2011/06/20/2085407.html
Android Relative Layout extension