Layout_weight of Android attribute Series

Source: Internet
Author: User

Record the layout_weight attribute that you know now. It is not comprehensive, but correct!

Layout_weight indicates "weight". My understanding is to set a display size ratio for the component.
When layout_weight is set to a value, two cases may occur.
First, when the "layout_width" attribute of the component is "fill_parent", the smaller the value, the larger the component.
Type 2: When the "layout_width" attribute of the component is "wrap_content", the larger the value, the larger the component.

First case:
XML Code
<Linearlayout
Android: layout_weight = "1"
Android: layout_width = "fill_parent"
Android: layout_height = "wrap_content"
Android: Orientation = "horizontal"
Android: layout_marginleft = "10dp"
Android: layout_marginright = "10dp"
>
<Button
Android: Id = "@ + ID/btn_save"
Android: layout_width = "fill_parent"
Android: layout_height = "wrap_content"
Android: layout_weight = "1"
Android: text = "save"
/>

<Button
Android: Id = "@ + ID/btn_return"
Android: layout_width = "fill_parent"
Android: layout_height = "wrap_content"
Android: layout_weight = "4"
Android: text = "return"
/>
</Linearlayout>

Here, when the "save" button's layout_weight = 1, "Return" button's layout_weight = 4, layout_width = "fill_parent", the running effect is:
 

Case 2:
XML Code
<Linearlayout
Android: layout_weight = "1"
Android: layout_width = "fill_parent"
Android: layout_height = "wrap_content"
Android: Orientation = "horizontal"
Android: layout_marginleft = "10dp"
Android: layout_marginright = "10dp"
>
<Button
Android: Id = "@ + ID/btn_save"
Android: layout_width = "wrap_content"
Android: layout_height = "wrap_content"
Android: layout_weight = "1"
Android: text = "save"
/>

<Button
Android: Id = "@ + ID/btn_return"
Android: layout_width = "wrap_content"
Android: layout_height = "wrap_content"
Android: layout_weight = "4"
Android: text = "return"
/>
</Linearlayout>

Here, when the "save" button's layout_weight = 1, "Return" button's layout_weight = 4, layout_width = "wrap_content", the running effect is:
 

The above is my summary of the known situations. If any of them is incorrect or cannot be summarized, please kindly advise!

The author is carrying his bag and moving forward alone ...."

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.