Linearlayout Android: layout_weight

Source: Internet
Author: User

An incorrect understanding

The Android: layout_weight of each view (such as button) is shown in the parent view as a proportional relationship.

2. self-understanding

Weight is the identifier of importance. The greater the value, the more important it is.

The higher the importance, the stronger the ability to occupy the remaining space of the parent view. The remaining space may be large, small, or even unavailable.

Three examples prove your understanding

<? XML version = "1.0" encoding = "UTF-8"?>

<Linearlayout xmlns: Android = "http://schemas.android.com/apk/res/android" Android: Orientation = "horizontal" Android: layout_width = "fill_parent" Android: layout_height = "fill_parent">

<Button Android: layout_weight = "1" Android: Id = "@ + ID/btn_ OK" Android: layout_width = "wrap_content"Android: text = "button11111111111111111111111111111"Android: layout_height = "wrap_content"> </button>

<Button Android: layout_weight = "2" Android: Id = "@ + ID/btn_ok2" Android: layout_width = "wrap_content" Android: text = "button2"Android: layout_height = "wrap_content"> </button>

<Button Android: layout_weight = "3" Android: Id = "@ + ID/btn_ok3" Android: layout_width = "wrap_content" Android: text = "button3"Android: layout_height = "wrap_content"> </button>

</Linearlayout>

Btn_ok3 is of the highest importance, so it has the strongest available space in the parent view. The parent view is first displayed with btn_ OK and btn_ok2. The display of the two views is displayed according to the required content space. No matter how much space is left, the display is allocated to btn_ok3.

Related Article

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.