Source:
http://zwkufo.blog.163.com/blog/static/2588251201011161220635/
Talk about Android to use five layout objects, they are framelayout (frame layout: Do not know is not so translated), LinearLayout (linear layout), Absolutelayout (absolute layout), Relativelayout ( Relative layout), tablelayout (table layout).
Framelayout:
Framelayout is one of the simplest layout objects. It is customized as a blank alternate area on your screen, after which you can populate a single object-for example, a picture you want to publish. All child elements will be pinned to the upper-left corner of the screen; You cannot specify a location for a child element in Framelayout. The latter child element will overwrite the padding directly above the previous child element, blocking them partially or completely (unless the latter element is transparent).
Let's take a look at:
Where the main.xml code is as follows:
<?xml version= "1.0" encoding= "Utf-8"?>
<framelayout xmlns:android= "Http://schemas.android.com/apk/res/android"
Android:layout_width= "Fill_parent"
android:layout_height= "Fill_parent"
>
<!--We've added a button here--
<button
android:text= "button"
Android:layout_width= "Fill_parent"
android:layout_height= "Wrap_content"
/>
<textview
android:text= "TextView"
Android:textcolor= "#0000ff"
Android:layout_width= "Wrap_content"
android:layout_height= "Wrap_content"
/>
</FrameLayout>
LinearLayout:
LinearLayout arranges all the child elements in the vertical or horizontal attribute values that you set for it. All child elements are stacked behind other elements, so that each row of a vertical list will have only one element, no matter how wide they are, and a horizontal list will have only one row high (height is the height of the highest child element plus the border height). LinearLayout keeps the spacing between child elements and aligns with each other (right-aligned, Middle-aligned, or left-aligned relative to an element).
LinearLayout also supports specifying weight for individual child elements. The benefit is that the child element can fill the remaining space on the screen. This also avoids the case of a bunch of small objects in a large screen, instead allowing them to enlarge the padding. The child element specifies a weight value, and the remaining space is assigned to those child elements at the weight scale specified by those child elements. The default weight value is 0. For example, if you have three text boxes, two of which specify a weight value of 1, the two text boxes will zoom in and out, filling the remaining space, and the third text box will not enlarge.
Let's take a look at:
Where the main.xml code is as follows:
<?xml version= "1.0" encoding= "Utf-8"?>
<linearlayout xmlns:android= "Http://schemas.android.com/apk/res/android"
android:orientation="Vertical"
Android:layout_width= "Fill_parent"
android:layout_height= "Fill_parent" >
<linearlayout
android:orientation="Vertical"
Android:layout_width= "Fill_parent"
android:layout_height= "Fill_parent"
android:layout_weight= "2" >
<textview
android:text= "Welcome to Mr Wei ' s blog"
Android:textsize= "15pt"
Android:layout_width= "Fill_parent"
android:layout_height= "Wrap_content"
/>
</LinearLayout>
<linearlayout
android:orientation="Horizontal"
Android:layout_width= "Fill_parent"
android:layout_height= "Fill_parent"
android:layout_weight= "1" >
<textview
android:text= "Red"
android:gravity= "Center_horizontal"//Here the word is horizontally centered
Android:background= "#aa0000"
Android:layout_width= "Wrap_content"
android:layout_height= "Fill_parent"
android:layout_weight= "1"/>
<textview
android:text= "Green"
android:gravity="Center_horizontal"
Android:background= "#00aa00"
Android:layout_width= "Wrap_content"
android:layout_height= "Fill_parent"
android:layout_weight= "1"/>
</LinearLayout>
</LinearLayout>
Absolutelayout:
absolutelayout allows child elements to specify accurate x/Y coordinate values and display them on the screen. (0, 0) is the upper-left corner, and when you move down or to the right, the coordinate value becomes larger. Absolutelayout does not have a page border, allowing elements to overlap each other (although not recommended). We don't usually recommend using Absolutelayout unless you have a legitimate reason to use it because it makes the interface code too rigid that it might not work well on different devices.
Let's take a look at:
Where the main.xml code is as follows:
<?xml version= "1.0" encoding= "Utf-8"?>
<absolutelayout xmlns:android= "Http://schemas.android.com/apk/res/android"
android:orientation= "Vertical"
Android:layout_width= "Fill_parent"
android:layout_height= "Fill_parent"
>
<edittext
Android:text= "Welcome to Mr Wei ' s Blog"
Android:layout_width= "Fill_parent"
android:layout_height= "Wrap_content"
/>
<button
android:layout_x= "250px"//Set the x-coordinate of the button
android:layout_y= "40px"//Set the y-coordinate of the button
android:layout_width= "70px"//Set the width of the button
android:layout_height= "Wrap_content"
android:text= "button"
/>
</AbsoluteLayout>
Relativelayout:
relativelayout allows child elements to specify their location relative to other elements or parent elements (specified by ID ). As a result, you can arrange two elements in the form of Right-aligned, or up or down, or centered on the screen. Elements are arranged sequentially, so if the first element is in the center of the screen, then the other elements relative to the element are arranged in the relative position of the center of the screen. If you use XML to specify this layout , the associated element must be defined before you can define it.
Let's take a look at:
Where the main.xml code is as follows:
<?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" >
<textview
android:id= "@+id/label"
Android:layout_width= "Fill_parent"
android:layout_height= "Wrap_content"
android:text= "Welcome to Mr Wei's blog:"/>
<edittext
android:id= "@+id/entry"
Android:layout_width= "Fill_parent"
android:layout_height= "Wrap_content"
android:layout_below= "@id/label"/>
<button
android:id= "@+id/ok"
Android:layout_width= "Wrap_content"
android:layout_height= "Wrap_content"
android:layout_below= "@id/entry"
Android:layout_alignparentright= "true"
android:layout_marginleft= "10dip"
android:text= "OK"/>
<button
Android:layout_width= "Wrap_content"
android:layout_height= "Wrap_content"
android:layout_toleftof= "@id/ok"
android:layout_aligntop= "@id/ok"
android:text= "Cancel"/>
</RelativeLayout>
Tablelayout:
Tablelayout assigns the position of the child element to a row or column. A tablelayout is made up of many TableRow , and each TableRow defines a row (in fact, you can define other sub-objects, as explained below). The tablelayout container does not display the row ,cloumns , or cell border lines. Each row has 0 or more cells , and each cell has a View object. A table consists of columns and rows that make up many cells. Table allows cells to be empty. Cells cannot span columns, which is not the same as in HTML .
Let's take a look at the following:
Where the main.xml code is as follows:
<?xml version= "1.0" encoding= "Utf-8"?>
<tablelayout xmlns:android= "Http://schemas.android.com/apk/res/android"
Android:layout_width= "Fill_parent" android:layout_height= "Fill_parent"
android:stretchcolumns= "1" >
<TableRow>
<textview android:layout_column= "1" android:text= "Open ..."/>
<textview android:text= "Ctrl-o"android:gravity= "right"/>
</TableRow>
<TableRow>
<textview android:layout_column= "1" android:text= "Save ..."/>
<textview android:text= "Ctrl-s"android:gravity= "right"/>
</TableRow>
<view android:layout_height= "2dip" android:background= "#FF909090"/>Here is the dividing line in the
<TableRow>
<textview android:text= "X"/>
<textview android:text= "Export ..."/>
<textview android:text= "CTRL-E"android:gravity= " right"/>
</TableRow>
<view android:layout_height= "2dip" android:background= "#FF909090"/>
<TableRow>
<textview android:layout_column= "1" android:text= "Quit"
android:padding= "3dip"/>
</TableRow>
</TableLayout>
The above is the Android five layout objects, the project is very large, a full one hours of my time, I hope that everyone has help ~ everyone more messages!
Android Five layout object--framelayout,linearlayout,absolutelayout,relativelayout,tablelayout