In-depth application of Android five-_android

Source: Internet
Author: User

Framelayout (frame layout),linearlayout (linear layout),absolutelayout(absolute layout),relativelayout(relative layout),tablelayout (Table layout)
Framelayout:
Framelayout is one of the simplest layout objects. It is customized to a blank standby area on your screen, and you can then populate it with a single object, such as a picture you want to post. All the child elements will be pinned to the upper-left corner of the screen; You cannot specify a location for a child element in the framelayout. The latter child element will cover the padding directly on top of the previous child element, blocking them partially or completely (unless the latter element is transparent).


Copy Code code 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 buttons 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>

The right picture is commonly used for video on demand, two pictures stacked together, the last one to cover the previous one, add link to the playback address;

LinearLayout:
LinearLayout arranges all the child elements in a vertical or horizontal attribute value 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, regardless of how wide they are, and a horizontal list will have only one row height (the height of the highest child element plus the height of the border). LinearLayout maintains the spacing between child elements and aligns with each other (relative to the right, center, or left-aligned of an element).

LinearLayout also supports the designation of weight for individual child elements . The benefit is to allow child elements to populate the remaining space on the screen. This also avoids the situation in a large screen where a bunch of small objects are squeezed into a pile, allowing them to enlarge the fill space. The child element specifies a weight value, and the remaining space is assigned to these child elements in the weight specified by the 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 proportionally and fill the remaining space, and the third text box will not zoom in.

Copy Code code as follows:

<linearlayout xmlns:android= "Http://schemas.android.com/apk/res/android"

Android:layout_width= "Match_parent"

android:layout_height= "Match_parent"

android:orientation= "Vertical" >

<linearlayout

Android:layout_width= "Fill_parent"

android:layout_height= "Fill_parent"

android:orientation= "Vertical"

android:layout_weight= "1" >

<textview

Android:layout_width= "Fill_parent"

android:layout_height= "Wrap_content"

Android:text= "Hello,welcome to Livingstone ' s blog"

Android:textsize= "15pt"/> </LinearLayout>

<linearlayout

Android:layout_width= "Fill_parent"

android:layout_height= "Fill_parent"

android:orientation= "Horizontal"

android:layout_weight= "2" >

<textview

Android:layout_width= "Wrap_content"

android:layout_height= "Fill_parent"

Android:layout_weight= "2"

Android:background= "#aa0000"

Android:gravity= "Center_horizontal"

android:text= "Red"/>

<textview

Android:layout_width= "Wrap_content"

android:layout_height= "Fill_parent"

android:layout_weight= "1"

Android:background= "#00aa00"

Android:gravity= "Center_horizontal"

android:text= "Green"/> </LinearLayout>

</LinearLayout>

Absolutelayout:

Absolutelayout you can have the child element specify the exact x/y coordinate value and display it on the screen. (0, 0) is the upper-left corner, and when moving down or to the right, the coordinate value becomes larger. Absolutelayout There is no page border, allowing elements to overlap (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 so rigid that it may not work well on different devices.
Relativelayout:
Relativelayout allows child elements to specify their location relative to other elements or parent elements (specified by ID ). Therefore, you can arrange two elements in the form of right alignment, up or down, or in the center of the screen. Elements are sorted sequentially, so if the first element is in the center of the screen, the other elements relative to the element will be 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.

Copy Code code as follows:

<linearlayout xmlns:android= "Http://schemas.android.com/apk/res/android"

Android:layout_width= "Match_parent"

android:layout_height= "Match_parent"

android:orientation= "Vertical" >

<linearlayout

Android:layout_width= "Fill_parent"

android:layout_height= "Fill_parent"

android:orientation= "Vertical"

android:layout_weight= "1" >

<textview

Android:layout_width= "Fill_parent"

android:layout_height= "Wrap_content"

Android:text= "Hello,welcome to Livingstone ' s blog"

Android:textsize= "15pt"/> </LinearLayout>

<linearlayout

Android:layout_width= "Fill_parent"

android:layout_height= "Fill_parent"

android:orientation= "Horizontal"

android:layout_weight= "2" >

<textview

Android:layout_width= "Wrap_content"

android:layout_height= "Fill_parent"

Android:layout_weight= "2"

Android:background= "#aa0000"

Android:gravity= "Center_horizontal"

android:text= "Red"/>

<textview

Android:layout_width= "Wrap_content"

android:layout_height= "Fill_parent"

android:layout_weight= "1"

Android:background= "#00aa00"

Android:gravity= "Center_horizontal"

android:text= "Green"/> </LinearLayout>

</LinearLayout>


tablelayout:

TablelayoutAssigns the position of a child element to a row or column. OneTablelayoutBy a lot ofTableRow, each TableRow will define a row (in fact, you can define other child objects, which is explained below). Tablelayout the container does not display a row,cloumns , or cell border line. Each row has 0 or more cell , and each cell has a View object. A table consists of a number of cells in columns and rows. The table allows cells to be empty. Cells cannot span columns, which is not the same as in HTML .


Copy Code code as follows:

<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"/>//This is the divider line in the figure above
<TableRow>
<textview android:text= "X"/>
<textview android:text= "Export ..."/>
<textview android:text= "ctrl-e" android:gravity= "right"/>//Let TextView appear on the right-hand side
</TableRow>
<view android:layout_height= "2dip" android:background= "#FF909090"/>
<TableRow>
<textview android:layout_column= "1" android:text= "Quit"
android:padding= "3dip"/>
</TableRow>
</TableLayout>

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.