Layout_weight usage and attention

Source: Internet
Author: User

Layout_weight usage and attention

Sometimes, you will always forget some things.

Now, write down the blog record when you are free.

I still remember the first time I used layout_weight, I thought the layout_weight attribute was used to separate the entire LinearLayout space.

Layout_weight means:

In the LinearLayout layout, the sub-control declares layout_weight, so the real layout_width of the sub-control is the proportion width of the remaining space + The layout_width attribute declared by the sub-control.

Assume that the LinearLayout width is L, and the sub-control width is L1, L2 ,......

Then the remaining space = L-L1-L2-... and the remaining space here can be negative.

Here are two examples:

 
 
  
  
  
 

Are you confused? Where did the android: text = "NEW BUTTON2" Button control go?

In fact, as I mentioned earlier, layout_weight:

Assume that the LinearLayout width is L.

The width of button1, 2, and 3 is L (because both are match_parent)

Then the remaining space width = L-3L =-2L

The proportion of button1 and button3 is 1/4, and the proportion of button2 is 2/4.

Buttonequalwidth = button3_width =-2L/4 + L = L/2

Button2_width =-2L * 2/4 + L = 0L

This is why button2 cannot be seen, while button1 and button3 account for half of each other.

In general, layout_weight is not used in this way. I just want to highlight its definition.

Layout_weight: In the LinearLayout layout, other child controls (without layout_weight) occupy a certain amount of space, and I want a child control to occupy the rest of the space, in this case, I may randomly use layout_weight = 1 in the Child control to achieve my goal.

For example:

 
 
  
  
  
 

 

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.