Android: layout_weight _ What is layout_weight

Source: Internet
Author: User

Layout_weight is used to assign importance values to multiple views in a linear layout.All views have a layout_weight value. The default value is 0, indicating that the value must be displayed.

The size of a view occupies the size of the screen space. If a value greater than zero is assigned, the parentThe available space in the image is separated. The split size depends on the layout_weight of each view.Value and the overall layout of the current screen, layout_weight value andThe percentage of the layout_weight value is determined. 

For example:

For example, we have a text label and two text editing elements in the horizontal direction.

The text label does not specify the layout_weight value, so it occupies the minimum space required.

If the layout_weight value of each of the two text editing elements is set to 1, the two are equally divided into the remaining width of the parent view layout (because we declare that the importance of the two is equal ).

If two In the text editing element, the first value of layout_weight is set to 1, and the second value is set to 2. 1/3 of the remaining space is allocated to the second one. the second is given to the first one (the smaller the value, higher importance ).

<Linearlayout Android: Orientation = "horizontal" Android: layout_width = "fill_parent" Android: layout_height = "fill_parent" Android: layout_weight = "1"> <textview Android: layout_width = "wrap_content" Android: layout_height = "fill_parent" Android: layout_weight = "1" Android: Background = "# aa0000" Android: gravity = "center" Android: TEXT = "1"/> <textview Android: layout_width = "wrap_content" Android: layout_height = "fill_parent" Android: layout_weight = "2" Android: Background = "#00aa00" Android: gravity = "center" Android: text = "1"/> <textview Android: layout_width = "wrap_content" Android: layout_height = "fill_parent" Android: layout_weight = "3" Android: background = "# tianaa" Android: gravity = "center" Android: text = "1"/> </linearlayout>

 

The effect is as follows:

 

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.