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: