Two examples of the greater the android:layout_weight and the smaller the proportion of the larger

Source: Internet
Author: User

Absrtact: My technical blog is often reproduced by rogue website malicious crawling. Please go to the original: http://www.cnblogs.com/hamhog/p/3907146.html, enjoy neat typography, effective links, correct code indentation, and a better reading experience.

about what the meaning of the android:layout_weight, "the larger the proportion of the Internet" and "the larger the proportion of the smaller" two claims. In fact both of these situations are also available.

Example 1:0DP

<LinearLayoutandroid:orientation= "vertical"Android:layout_width= "Match_parent"Android:layout_height= "Match_parent">    <TextViewAndroid:layout_width= "Fill_parent"Android:layout_height= "0DP"Android:background= "#ff0000"Android:layout_weight= "1"Android:text= "1"/>    <TextViewAndroid:layout_width= "Fill_parent"Android:layout_height= "0DP"Android:background= "#00ff00"Android:layout_weight= "2"Android:text= "2"/></LinearLayout>

Example 2:

<LinearLayoutandroid:orientation= "vertical"Android:layout_width= "Match_parent"Android:layout_height= "Match_parent">    <TextViewAndroid:layout_width= "Fill_parent"Android:layout_height= "Match_parent"Android:background= "#ff0000"Android:layout_weight= "1"Android:text= "1"/>    <TextViewAndroid:layout_width= "Fill_parent"Android:layout_height= "Match_parent"Android:background= "#00ff00"Android:layout_weight= "2"Android:text= "2"/></LinearLayout>

Explanation of the two situations:

The layout first assigns a width to each element, and the remaining space is allocated to each element.

In the allocation width phase, the proportions are based on the reciprocal of Layout_weight, that is, the smaller the more Oita.

In allocating the remaining space phase, the proportions are in accordance with layout_weight, that is, the greater the larger the Oita.

In case one, the fixed width is 0, only the second stage; In case two, the allocation width can fill all the space, only the first stage.

So if you want to strictly let it in a certain proportion, you can try to set it to 0DP. At this point the proportions of each element are weight.

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.