"Alearning" chapter fourth Android layout component layout (i)

Source: Internet
Author: User

In this chapter, we will learn the components layout of Android. In the previous chapters, we also started using the LinearLayout layout. Then we in the layout file more specific learning and understanding, will.

The Android interface is finished with layout and component coordination, and the layout is like a frame in the building, and the components are the bricks in the building. The components are arranged according to the layout requirements. It makes up the interface that the user sees.

The five layouts of Android are linearlayout (linear layout), Framelayout (single frame layout), relativelayout (relative layout), Absolutelayout (absolute layout) and tablelayout (table layout).

1. Linear layout (LinearLayout)
Linear layout of the form can be divided into two, the first horizontal linear layout of another longitudinal linear layout, in short, all are arranged in linear form, the disadvantage of pure linear layout is very inconvenient to change the display position of the control, so the development often in the form of linear layout and relative layout nested format layout.
2. Frame Layout (framelayout)
The principle is that the control is drawn, regardless of what one control can be overridden by a control that is drawn later, and the last control that is drawn will cover the previous control.


3. Absolute layout (absolutelayout)
You can use absolute layout to set the X Y coordinate point of a discretionary control in the screen, and a control that is drawn after the same frame layout overrides the previously drawn control.
4. Relative layout (relativelayout)
The relative layout is the most powerful in the Android layout. The first thing it can set is the maximum number of properties, and secondly it can do the most things. Android phone screen resolution of a variety of so in order to consider the screen adaptive situation, so in the development of the proposed to use the relative layout of its coordinate range is relative, so use it to do the adaptive screen is correct.
5. Table layout (tablelayout)
You can set TableRow in a table layout to set the content and position of each row in the table, and to set the indentation for the display. The way to align.

"Blog column: http://blog.csdn.net/column/details/alearning.html"

linearlayout (linear layout)The LinearLayout arranges the child elements in a vertical or horizontal order. Each child element is positioned after the previous element. Not only linearlayout layouts can be nested in use. Other layouts can be used in a nested manner as well.

The function of the child element attribute Android:layout_weight in LinearLayout is to describe the proportion of the child element occupying in the remaining space, and the default value is 0.
This example expands the property configuration as follows:

    • Android:layout_weight weight
Assuming that there are two unequal text boxes (TextView, etc.) in LinearLayout, their android:layout_weight values are 1 and 2, respectively, and the first text box will occupy two-thirds of the remaining space. The second text box will occupy one of the three points in the remaining space. Android:layout_weight follows the principle that the smaller the value, the higher the importance. This example demonstrates that the android:layout_weight is 1. So the average distribution width of two linearlayout.
"Layout file" Activity_linearlayout.xml
<linearlayout 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:gravi ty= "center" android:orientation= "vertical" tools:context= ".        Mainactivity "> <!--single linearlayout-<linearlayout android:layout_width=" Match_parent "        android:layout_height= "Wrap_content" android:background= "#99CCFF" android:orientation= "Horizontal" > <textview android:layout_width= "match_parent" android:layout_height= "80DP" Android: gravity= "center" android:text= "#99CCFF"/> </LinearLayout> <!--a single linearlayout including two horizontal, evenly spaced lin Earlayout--<linearlayout android:layout_width= "match_parent" android:layout_height= "wrap_content "android:orientation=" Horizontal "> <linearlayout android:layout_width="Match_parent "android:layout_height=" Wrap_content "android:layout_weight=" 1 "android:back Ground= "#CCFF66" android:orientation= "vertical" > <textview Android:layout_widt H= "Match_parent" android:layout_height= "60DP" android:gravity= "center" Androi             d:text= "#CCFF66"/> </LinearLayout> <linearlayout android:layout_width= "Match_parent" android:layout_height= "Wrap_content" android:layout_weight= "1" android:background= "#FF99 XX "android:orientation=" vertical "> <textview android:layout_width=" match_pare NT "android:layout_height=" 60DP "android:gravity=" center "android:text=" #FF99 "/> </LinearLayout> </LinearLayout> <!--The above two cases---<linearlayout and Roid:layout_width= "Match_parent "android:layout_height=" wrap_content "android:orientation=" Horizontal "> <linearlayout Android:layout_width= "Match_parent" android:layout_height= "Wrap_content" Android:layout_w                eight= "1" android:background= "#CC99CC" android:orientation= "vertical" > <textview Android:layout_width= "Match_parent" android:layout_height= "120DP" Android:grav ity= "center" android:text= "#CC99CC"/> </LinearLayout> <linearlayout A            Ndroid:layout_width= "Match_parent" android:layout_height= "Wrap_content" android:layout_weight= "1" android:orientation= "vertical" > <linearlayout android:layout_width= "match_parent "Android:layout_height=" wrap_content "android:background=" #CC9933 "Android:o rientation= "Horizontal"> <textview android:layout_width= "match_parent" Android:layout_ height= "60DP" android:gravity= "center" android:text= "#CC9933"/> </ linearlayout> <linearlayout android:layout_width= "Match_parent" Android:lay                 out_height= "Wrap_content" android:background= "#99CCCC" android:orientation= "Horizontal" > <textview android:layout_width= "Match_parent" Android:layout_heig ht= "60DP" android:gravity= "center" android:text= "#99CCCC"/> </line Arlayout> </LinearLayout> </LinearLayout></LinearLayout>

Effect:

framelayout (frame layout)Framelayout is the simplest layout in the five layouts where the entire interface is treated as a blank spare area. All child elements cannot be placed in the specified position. They are all placed in the upper-left corner of the area, and the subsequent child elements are directly above the preceding child elements, and the preceding child elements are partially and all obscured.
This example expands the property configuration as follows:
    • Android:gravity the base position of the specified control
Note: This property has been introduced before, this example is special. This is intended to illustrate the assumption that two parameters are specified for this attribute. Can be used in the following format, with "|" Connection.
Android:gravity= "Bottom|center"

"Layout file" Activity_framelayoutt.xml
<?xml version= "1.0" encoding= "Utf-8"? ><framelayout xmlns:android= "http://schemas.android.com/apk/res/ Android "    android:layout_width=" match_parent "    android:layout_height=" match_parent ">    <textview android:layout_height= "Match_parent"        android:background= "#99CCFF"        android:layout_width= "Match_parent"        android:gravity= "Bottom|center"        android:text= "first layer \ \" #99CCFF ""/>         <textview android:layout_ height= "200DP"         android:background= "#CC99CC"        android:layout_width= "200DP"        android:gravity= "bottom |center "        android:text=" second level \ n "#CC99CC" "/>     <textview android:layout_height=" 100DP "        android: Layout_width= "100DP"        android:gravity= "Bottom|center"        android:background= "#99CCCC"        android:text= "Third tier \ \" #99CCCC ""/>     </FrameLayout>
Effect:

watermark/2/text/ahr0cdovl2jsb2cuy3nkbi5uzxqvbwfob2tpbmc=/font/5a6l5l2t/fontsize/400/fill/i0jbqkfcma==/ Dissolve/70/gravity/center ">
Absolutelayout (absolute layout) absolutelayout is an absolute position layout.

The android:layout_x and Android:layout_y properties of the child elements in this layout take effect and are used to describe the coordinates where the child element is described. The upper-left corner of the screen is the coordinate origin (0,0). The first 0 represents the horizontal axis, moves to the right this value increases, the second 0 represents the ordinate, moves down, this value increases.

Child elements in this layout can overlap each other. In the actual development, this layout is usually not used, because its interface code is too rigid, so that there is not very good to adapt to a variety of terminal equipment.


This example expands the property configuration as follows:

    • Android:layout_x the position of the x-axis of the specified control
    • Android:layout_y the position of the y-axis of the specified control
"Layout file" Activity_absolutelayout.xml.
<?

XML version= "1.0" encoding= "Utf-8"?

><absolutelayout xmlns:android= "http://schemas.android.com/apk/res/android" android:layout_width= "Match_ Parent "android:layout_height=" match_parent "> <textview android:layout_width=" 60DP "Android:lay out_height= "60DP" android:layout_x= "30DP" android:layout_y= "30DP" android:background= "#009966" android:text= "#009966"/> <textview android:layout_width= "60DP" android:layout_height= "60DP" android:layout_x= "90DP" android:layout_y= "80DP" android:background= "#CC6699" android:text= "#CC6699" /> <textview android:layout_width= "60DP" android:layout_height= "60DP" android:layout_x= "30d P "android:layout_y=" 180DP "android:background=" #3366CC "android:text=" #3366CC "/> <textview Android:layout_width= "60DP" android:layout_height= "60DP" android:layout_x= "180DP" Android:lay Out_y= "90DP" android:backgRound= "#FFCC99" android:text= "#FFCC99"/> <textview android:layout_width= "60DP" Android:layo ut_height= "60DP" android:layout_x= "240DP" android:layout_y= "200DP" android:background= "#FF6666" android:text= "#FF6666"/></absolutelayout>


Effect:

References

1, http://blog.chinaunix.net/uid-23544029-id-2985631.html

2, http://www.cnblogs.com/wisekingokok/archive/2011/08/23/2150452.html

3, http://blog.csdn.net/jzp12/article/details/7590591



"Alearning" chapter fourth Android layout component layout (i)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.