Android development ------ linear layout of user interfaces (additional knowledge)

Source: Internet
Author: User

Http://www.cnblogs.com/ai-developers/p/android_linearlayout.html in previous article

We can see that the layout has such an attribute:

Layout_weight = "1"

What is its role.

First, let's take a look at the running effect of the lower-layer code in the pipeline.

View Code

Five buttons are defined here, but there are two overflows, which are invisible.
      

The code is improved to add a layout_weight attribute for each element.

View Code

Run it again and try again. Now the program requirements are met, but we find that the height of each button has changed, and the layout_height attribute does not work.

        

Can we delete the layout_height attribute. The answer is no. The program will crash. The following is the logCat error message:

  

Our layout file must provide the layout_width and layout_height attributes.

How the layout_weight attribute works:

Layout_weight: Set the percentage of screen space occupied by each view. For example, if the orientation value is vertical and there are three buttons, their layout_weight values are respectively 1, 2, 3. The layout_height space they own is button1 = 1/(1 + 2 + 3) * 100% button2 = 2/(1 + 2 + 3) * 100% button3 = 3/(1 + 2 + 3) * 100% now we have five buttons, all of which are layout_weight values of 1, then their height is button = 1/(1 + 1 + 1 + 1 + 1) * 100% = 20% Support originality. For reprint, please indicate the source.Http://www.cnblogs.com/ai-developers/p/android_layout_weight.html

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.