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