Types of layouts for Android:
Main:linearlayout (Linear layout),relativelayout (relative layout), tablelayout (table layout), Absolutelayout (absolute layout), Framelayout (single frame layout).
1. linearlayout (Linear layout): is one of the most common types of 5 layouts that, when displayed, will default to keep the interval between components and the alignment of components to each other.
(1) Display component two ways: vertical (vertical) and horizontal (horizontal), is set by orientation.
<?xml version= "1.0" encoding= "Utf-8"? ><linearlayout xmlns:android= " Http://schemas.android.com/apk/res/android "android:layout_width=" fill_parent "android:layout_height=" Fill_ Parent "android:orientation=" vertical "//vertical arrangement (horizontal horizontal)
> <button android:layout_width=" fi Ll_parent "android:layout_height=" wrap_content "android:text=" Button1 "/> <button an Droid:layout_width= "Fill_parent" android:layout_height= "wrap_content" android:text= "Button2"/> <button android:layout_width= "fill_parent" android:layout_height= "wrap_content" android:text= "Bu Tton3 "/></LINEARLAYOUT>
(2) can be nested using linear layouts.
<?xml version= "1.0" encoding= "Utf-8"? ><linearlayout xmlns:android= "http://schemas.android.com/apk/res/ Android " android:layout_width=" fill_parent " android:layout_height=" fill_parent " android:o rientation= "Horizontal" > <button android:layout_width= "wrap_content" android:layout_height= " Wrap_content " android:text=" Button1 " /> <linearlayout android:orientation=" vertical " android:layout_width= "fill_parent" android:layout_height= "fill_parent" > <button android:layout_width= "wrap_content" android:layout_height= "wrap_content" android:text= "Button2 " /> <button android:layout_width=" wrap_content " android:layout_height=" wrap_content " android:text=" @string/button3 " /> </LinearLayout></LinearLayout>
Summary: Some of the commonly used properties in linear layouts are as follows
1) Android:id-Specify the appropriate ID for the control (for example: android:id= "@+id/txt")
2) Android:text-Specify the text displayed in the control, and note that use String.xml as much as possible (e.g. Android:text = "@string/hello_world")
3) android:gravity-Specifies the base position of the control, such as center, right, etc. (e.g. android:gravity="center_vertical" )
Android:layout_gravity-is relative to its parent element, stating where the element appears in the parent element.
Each component defaults to its top-left alignment, and its properties can be adjusted to align components such as left, right, or center alignment.
The optional values are: top, bottom, left, right, center_vertical, fill_vertical, Center_horizontal, fill_horizontal, center, fill, Clip_ Vertical
and these properties are available in multiple selections, with the "|" Separate. the default value for this is: Gravity.left.
When android:orientation= "vertical", only the horizontal setting will work, and the vertical setting will not work. That is: The left,right,center_horizontal is in force.
When android:orientation= "Horizontal", only the vertical setting will work, and the horizontal setting will not work. That is: The top,bottom,center_vertical is in force.
4) Android:textsize-Specifies the size of the font in the control (for example, android:textsize="15pt" )
5) Android:background-Specifies the background color used by the control, the RGB nomenclature (android:background="#aa0000" )
6) Android:layout_width-Specifies the width of the control (for example, android:layout_width="fill_parent")
Generally "fill_parent", "Wrap_content", "match_parent", you can also set the value.
7) Android:layout_height-Specifies the height of the control (for example, android:layout_height="wrap_content")
Generally "fill_parent", "Wrap_content", "match_parent", you can also set the value.
8) Android:layout_weight-Specifies the control's occupancy ratio (for example, android:layout_weight="2" )
The default is zero, and its properties represent how large a view is currently, and if its value is higher than zero, the space available in the parent view is split, and the size of the split depends on the layout_weight value of the current screen's overall layout and the Layout_weight value of each component.
9) android:padding-Specifies the inner margin of the control, that is, the contents of the control (for example:android:paddingleft="10dip" )
There are five kinds of paddingtop, paddingbottom, paddingleft, paddingright and padding.
Android:sigleline-If set to true, the contents of the control are displayed in one row (for example, android:singleline="true" )
One) Android:layout_margin, outer margin, its upper and lower left and right properties are: Layout_margintop,layout_marginbottom,layout_marginleft,layout_ MarginRight
Note: In a linear layout
[1] The property with "layout" refers to the relationship between the entire control and the parent control, such as the alignment of Layout_gravity in the parent control, Layout_margin is the same level of the gap between the controls, and so on;
[2] The property without "layout" is the format of the text in the accusation, such as gravity refers to the alignment of the text and so on, where the format of the text is constrained by its control in the parent control of the property.
2,relativelayout (relative layout)
<?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= "Fill_ Parent "> <button android:layout_width=" wrap_content "android:layout_height=" Wrap_content " android:text= "Button1" android:id= "@+id/btn1"/> <button android:layout_width= "Fill_pare NT "android:layout_height=" Wrap_content "android:text=" Button2 "android:id=" @+id/btn2 "Android : layout_below= "@id/btn1"/> <button android:layout_width= "Wrap_content" Android:layout_heig ht= "Wrap_content" android:text= "Button3" android:id= "@+id/btn3" android:layout_below= "@id/btn2" android:layout_alignright= "@id/btn2"/> </relativelayout>
Summary: Relative layout Common Properties
(1) The position relationship between components:
[1]android:layout_above: The control at the bottom of the control is above the given ID;
[2]android:layout_below: The top of the control is the control of the given ID;
[3]android:layout_toleftof: Aligns the right edge of the control with the left edge of the control for the given ID;
[4]android:layout_torightof: Aligns the left edge of the control with the right edge of the control for the given ID;
(2) Alignment of components:
[1]android:layout_alignbaseline: The baseline alignment of the control's baseline and the given ID of the control;
[2]android:layout_alignbottom: Aligns the bottom edge of the control with the bottom edge of the given ID control;
[3]android:layout_alignleft: Aligns the left edge of the control with the left edge of the given ID control;
[4]android:layout_alignright: Aligns the right edge of the control with the right edge of the given ID control;
[5]android:layout_aligntop: Aligns the top edge of the given control with the top of the given ID control;
(3) How the current component is aligned with the parent component:
[1]android:alignparentbottom:true, aligns the bottom of the control with the bottom of the parent control;
[2]android:layout_alignparentleft:true, the left side of the control is aligned with the left side of the parent control;
[3]android:layout_alignparentright:true, the right side of the control is aligned with the right side of the parent control;
[4]android:layout_alignparenttop:true, aligns the top of the space with the top of the parent control;
(4) Position of component placement:
[1]android:layout_centerhorizontal:true, the control will be centered in the horizontal direction;
[2]android:layout_centerinparent:true, the control will be centered in the horizontal and vertical direction of the parent control;
[3]android:layout_centervertical:true, the control will be in the vertical direction of the middle central ;
Android Layout (i)