Android UI Component LinearLayout Linear layout detailed _android

Source: Internet
Author: User

linearlayout Linear Layout , the inheritance relationship of this layout:


1. What is a linear layout
Popular said that feeling and the line, the characteristics of the reference line, there is no horizontal, or vertical.
A linearlayout is a linear layout control that contains child controls that are arranged horizontally or vertically (controlled by the Android:orientation property), arranging all widgets or other containers by relative position, and exceeding the boundary, Some controls will be missing or disappear
2. Linear Layout Common basic properties
-Android:id
-Android:orientation
-Android:layout_height
-Android:layout_width
-Android:gravity
-Android:layout_gravity
-Android:background
-Android:layout_margin:
-Android:padding
-Android:weightsum
-Android:layout_weight
-android:baselinealigned
3. Introduction of common attribute values:
Android:id:
This is the unique identification ID of the layout
android:orientation: He says that the linear layout is a horizontal or vertical layout, usually with only two values:
1. android:orientation= "vertical" means portrait layout, all controls added in the current layout are arranged vertically


2. android:orientation= "Horizontal" means a landscape layout in which all controls added in the current layout are arranged horizontally (default level)

Android:layout_height: represents the height of the current linear layout

4. Android:layout_height= "Match_parent" (indicates height fills the entire screen)
5. Android:layout_height= "Wrap_content" (indicates that the height is adaptively adjusted according to the controls it contains)
6. Android:layout_height= "30DP" (custom set height, usually in units of DP)

Android:layout_width: represents the width of the current linear layout

7. Android:layout_width= "Match_parent" (indicates that the width fills the entire screen)
8. Android:layout_width= "Wrap_content" (indicates that the width is adaptively adjusted according to the controls it contains)
9. Android:layout_width= "30DP" (custom set width, usually in units of DP)

android:gravity: indicates that all controls contained in the current layout are aligned in some way (left justified by default)



From the top down, turn to:
Center (vertical and horizontally centered)
Center_horizontal (horizontally centered)
Bottom (bottom alignment)
Center_vertical (vertically centered)
Clip_horizontal (horizontally trimmed, cut off the top and bottom edges when the object edge is out of the container, cut based on the vertical alignment setting: When the top is aligned, cut at the base, cut at the bottom when aligned, and cut on top and bottom in addition)
Clip_vertical (crop vertically, cut off the left and right edges when the edge of the object is out of the container, cut on the left side when aligned, and cut the left part when the right is aligned; the left and right part of the cut.)
End (put in the ending position of the container without changing its size)
Fill (Increase the horizontal vertical size of the object when necessary to fully fill its container)
Fill_horizontal (Increase the horizontal size of the object when necessary to fully fill its container.) in a horizontal direction
Fill_vertical (Increase the vertical size of the object when necessary to fully fill its container.) Vertical padding
Left (place the object on the left-hand side of its container without changing its size)
Right (place the object on the right-hand side of its container without changing its size)
Start (Places the object at the beginning of its container without changing its size)
Top (Place the object at the front of its container without changing its size)

android:layout_gravity: represents the alignment of the current linear layout relative to the parent element
As shown above
Android:background: represents the background color of the current linear layout
android:margin: outer margin, usually representing the distance between this control and the parent control


From top down:
1. Bottom margin
2. Margins with the end of the control
3. Left margin
4. Right margin
5. The start margin of the control
6. Top margin

android:padding: represents an inner margin, usually representing the distance from the edge of the parent element of all child elements of this element, set on the parent element, such as all the distance between text and text controls


From the top down as shown above
android:weightsum: total proportion of weights
android:layout_weight: The weight of the child element to the unoccupied space horizontal or vertical distribution

<?xml version= "1.0" encoding= "Utf-8"?> <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" tools:context= "com.qianfeng.demo1.MainActivity" android:weightsum= "6"//The total weight is 6 android:orientation = "vertical" > <textview android:layout_width= "match_parent" android:layout_height= "0DP" android:layout_weight = "2"//This control occupies a scale of 2, the other controls occupy a total of 1, the weight of more than proportional does not allocate the corresponding size, equivalent to the size of 0 android:textsize= "30sp" android:text= "AAAA" Android: background= "#f00" p/> <textview android:layout_width= "match_parent" android:layout_height= "0DP" android:layou t_weight= "1" android:textsize= "30sp" android:text= "bbbb" android:background= "#0f0"/> <textview android:layout _width= "Match_parent" android:layout_height= "0DP" android:layout_weight= "1" android:textsize= "30sp" Android: Background= "#00f" android:text= "CCCC"/> <textview android:laYout_width= "Match_parent" android:layout_height= "0DP" android:layout_weight= "1" android:textsize= "30sp" Android: text= "dddd" android:background= "#0ff"/> <textview android:layout_width= "Match_parent" android:layout_height= "0DP" android:layout_weight= "1" android:textsize= "30sp" android:background= "#f0f" android:text= "eeee"/> </Lin
 Earlayout>

The effect chart is as follows:

android:baselinealigned: This control is valid only for child controls that can display text.
This must be a Boolean value, either "true" or "false" and prevents the layout from adjusting its child's baseline. The default is True

Here's a little detail:

Here with the vertical allocation of the weight of columns, the weight can be negative, the weight is based on proportional distribution of the corresponding size, here AAAA control high for the 0dp,bbbb control of the high 0DP, so, AAAA control allocation weight is 5,BBBB allocation weight is 1, So AAAA here will be larger than the bbbb occupancy ratio.

<?xml version= "1.0" encoding= "Utf-8"?> <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"
 tools:context= "com.qianfeng.demo1.MainActivity"
 android:weightsum = "6"
 android:orientation= "vertical"
 >
 <textview
 android:layout_width= "Match_parent"
 android:layout_height= "0DP"
 android:layout_weight= "5"
 android:textsize= "30sp"
 android: text= "AAAA"
 android:background= "" #f00 "
 />
 <textview android:layout_width="
 Match_ Parent "
 android:layout_height=" 0DP "
 android:layout_weight=" 1 "
 android:textsize=" 30sp
 " android:text= "bbbb"
 android:background= "#0f0"
 />

</LinearLayout>


Effect Chart:

Conversely, if the AAAA control is set to Match_parent, the height of the BBBB control is also assigned the weight of the MATCH_PARENT,AAAA control is the 5,BBBB allocation weight is 1, thus creating a reverse effect, the equivalent of the AAAA control is allocated to 5 The bbbb control allocates 1 and-1 to 5, so the corresponding BBBB control occupies a larger proportion than AAAA

<?xml version= "1.0" encoding= "Utf-8"?> <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"
 tools:context= "com.qianfeng.demo1.MainActivity"
 android:weightsum = "6"
 android:orientation= "vertical"
 >
 <textview
 android:layout_width= "Match_parent"
 android:layout_height= "match_parent"
 android:layout_weight= "5"
 android:textsize= "30SP"
 android:text= "AAAA"
 android:background= "#f00"
 />
 <textview
 android:layout_width= " Match_parent "
 android:layout_height=" match_parent "
 android:layout_weight=" 1 "
 android:textsize=" 30SP "
 android:text=" bbbb "
 android:background=" #0f0 "
 />

</LinearLayout>

The effect chart is as follows:

The above is the entire content of this article, I hope to help you learn, but also hope that we support the cloud habitat community.

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.