LinearLayout of Android UI (linear layout)

Source: Internet
Author: User

Description: A linear layout is the most commonly used layout, and all of the view contained in it is arranged in linear order.
It is important to note that there are four more commonly used XML attributes:

1 android:gravity

Corresponding method:setgravity (int)
Description: This property sets the alignment of components within the layout and supports the following property values:

Property Value function
Top Place an object at the top of its container without changing its size
Bottom Place an object at the bottom of its container without changing its size
Left Place an object on the left side of its container without changing its size
Right Place an object on the right side of its container without changing its size
Left Place an object on the left side of its container without changing its size
Center_vertical Center the object vertically without changing its size
Center_horizontal Center the object horizontally, without changing its size
Center Center the object vertically, without changing its size
Fill_vertical When necessary, increase the vertical size of the object to fully fill its container
Fill_horizontal When necessary, increase the horizontal size of the object to fully fill its container
Fill When necessary, increase the horizontal longitudinal size of the object to fully fill its container
Clip_vertical Additional options for cutting the contents of the top and/or bottom of the object according to the edges of the container. Clipping is based on its vertical alignment settings: When the top is aligned, the bottom is clipped, the top is clipped at the bottom, and the top and bottom are cut apart.
Clip_horizontal An additional option to cut the contents of the left and/or right of the object according to the edges of the container. Clipping is based on its horizontal alignment settings: Cut to the right when left aligned, cut to the left when aligned to the right, and cut to the left and right.

The above attribute values can be selected in the middle with "|" Separated.

2 android:orientation

Corresponding method:setorientation (int)
Description: This property sets the arrangement of layouts in LinearLayout, supports both horizontal (horizontal arrangement) and vertical (vertically arranged) property values, which are vertically arranged by default.

Note: It should be noted that the value of orientation affects the settings of gravity.
only when the orientation is set to vertical, the layout related to the horizontal direction can be used, for example: left;
only if the orientation is set to horizontal, the layout that is related to the vertical direction can be used, for example: bottom;
That is, only gravity property values that are reversed from the orientation value can function

3 android:layout_gravity

Description: Look at the name is similar to android:gravity, but there is a difference between the two.
Android:gravity is the setting of the position of the content in the view, for example: the position of the button in the LinearLayout, the default is from the upper left corner;
Android:layout_gravity is relative to the view's parent view, which shows where the element appears in the parent view, such as: Button wants to be placed at the bottom of the linearlayout.

4 Android:weight

Description: Specifies the weight of the change view in the LinearLayout.
The weight here is the proportion of the remaining space after the component is allocated.

Note: When actually developing, we cannot set the width/height in the direction that the group price needs to be set weights.
details can go to Xiaanming's blog to understand, here do not do too much explanation
So, if we want the components to be scaled horizontally, we need to set the component's Android:layout_width property to 0dp.

Attached: Citation statement

Grasshopper June's technical experience: the difference between android:layout_gravity and android:gravity
Mobile Internet developer:android Full parsing of layout_weight properties and using ListView to implement tables
"Crazy Android Handout (second edition)" Li Gang "2.2.1 Linear layout" electronic industry Press

LinearLayout of Android UI (linear layout)

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.