LinearLayout of Android layout controls

Source: Internet
Author: User

LinearLayout of Android layout controls

LinearLayout is a linear layout control that contains child controls that are arranged in a horizontal or vertical manner, with all widgets or other containers arranged in a relative position, and some controls will be missing or disappear when the boundary is exceeded. So each line of a vertical list will have only one widget or container, no matter how wide they are, and a horizontal list will have only one row high (height is the height of the highest child control plus the border height). The linearlayout maintains the spacing between the widgets it contains or the container and aligns with each other (right-aligned, Middle-aligned, or left-aligned relative to a control).

XML properties

Android:baselinealigned: Whether the user is allowed to adjust the baseline of its content.

Android:baselinealignedchildindex: When a linear layout is part of a baseline alignment with another layout, it can specify the baseline alignment of its content.

Android:gravity: Specifies how to place the contents of this object (x/Y coordinate values) in the object.

Android:orientation: Sets the orientation of its contents (landscape/vertical).

Gravity This English word is the meaning of the center of gravity, here means the docking position.

The difference between android:layout_gravity and android:gravity

As you can see from the name, Android:gravity is the element itself, where the text of the element itself is displayed in a different property setting, but not set by default on the left.

Android:layout_gravity is relative to its parent element, stating where the element appears in the parent element.

For example, button:android:layout_gravity represents the position of the button on the interface. The android:gravity represents the position of the word on the button on the button.

Optional values

The optional values for these two properties are: Top, bottom, left, right, center_vertical, fill_vertical, Center_horizontal, fill_horizontal, center, fill, Clip_vertical.

And these properties are available in multiple selections, with the "|" Separate.

The default value for this is: Gravity.left

LinearLayout also supports specifying padding weights for the widgets or container that it contains. The advantage is that it allows the widget or container that it contains to fill the remaining space on the screen. This also avoids the case of a bunch of widgets or containers in a large screen, allowing them to enlarge the padding. The remaining space is assigned a screen according to the weights specified by these widgets or containers. The default weight value is 0, which indicates that the widgets or containers actual size, if higher than 0, will container the remaining free space, split the size depending on each widget or container layout_ Weight and the proportion of that weight in all widgets or containers. For example, if you have three text boxes, where two of the weights you specify are 1, then the two text boxes will zoom in and fill the remaining space, and the third text box will not enlarge to show the actual size. If the first two text boxes are given a value of 2, one is 1, the remaining space after the third text box is displayed, the 2/3 weight of the room is 2, and the 1/3 size is 1. The greater the weight, the greater the importance.

If LinearLayout contains sub-linearlayout, the greater the weight between the sub-linearlayout, the less important. If there is a weight value of 2,d for LinearLayout A that contains linearlayout c,d,c, then the 1 of the screen's 2/3 space is given a value of 1 for the D,1/3 to the weight of 2 C. In the case of linearlayout nesting, the child linearlayout must set the weight, otherwise the default is not set the weight of the child linearlayout occupy the entire screen

1.

<?xml version= "1.0" encoding= "Utf-8"?>

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

android:orientation= "Horizontal"

Android:baselinealigned= "true"

Android:layout_width= "Fill_parent"

android:layout_height= "Fill_parent"

>

<button

Android:layout_width= "Wrap_content"

android:layout_height= "Wrap_content"

android:text= "Button 1"

/>

<button

Android:layout_width= "Wrap_content"

android:layout_height= "Wrap_content"

android:text= "Button 2"

/>

<button

Android:layout_width= "Wrap_content"

android:layout_height= "Wrap_content"

android:text= "Button 3"

/>

</LinearLayout>

2.

<?xml version= "1.0" encoding= "Utf-8"?>

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

android:orientation= "Vertical"

Android:baselinealigned= "true"

Android:layout_width= "Fill_parent"

android:layout_height= "Fill_parent"

>

<button

Android:layout_width= "Wrap_content"

android:layout_height= "Wrap_content"

android:text= "Button 1"

/>

<button

Android:layout_width= "Wrap_content"

android:layout_height= "Wrap_content"

android:text= "Button 2"

/>

<button

Android:layout_width= "Wrap_content"

android:layout_height= "Wrap_content"

android:text= "Button 3"

/>

</LinearLayout>

3.

<?xml version= "1.0" encoding= "Utf-8"?>

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

android:orientation= "Vertical"

Android:baselinealigned= "true"

Android:layout_width= "Fill_parent"

android:layout_height= "Fill_parent"

Android:gravity= "Center_horizontal"

>

<button

Android:layout_width= "Wrap_content"

android:layout_height= "Wrap_content"

android:text= "Button 1"

/>

<button

Android:layout_width= "Wrap_content"

android:layout_height= "Wrap_content"

android:text= "Button 2"

/>

<button

Android:layout_width= "Wrap_content"

android:layout_height= "Wrap_content"

android:text= "Button 3"

/>

</LinearLayout>


LinearLayout of Android layout controls

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.