The use of the wirelessly Layout_weight attribute is always a blur for many developers, and the code that is written often fails to achieve the desired effect. On the Internet to check some information after oneself also wrote a small demo after the Layout_weight attribute has a basic grasp. Here is a brief introduction:
First, the basic principle
First the Layout_weight property is only applicable in LinearLayout, the system first allocates the space occupied by each control in layout to each control, and the remaining space on the screen is the rest. The remaining space is then allocated to each control based on the proportion of the layout_weight of each control. If the remaining space is negative, the corresponding portion of the current control's occupied space is also calculated proportionally, which is precisely when the control's width is fill_parent for each control in the layout orientation direction, and the resulting controls are allocated proportional to the Layout_ Weight property value The opposite reason (when each control is fill_parent, the remaining space must be negative, at this time the remaining space allocated by the control is also negative, the proportion of small minus the area is small so the final remaining area is relatively large)
Second, the use of skills
1, when the need for the control of equal distribution, you can use wrap_content and the same weight value, if the use of fill_parent often can not achieve the effect.
2, when you need to implement a control to fill the remaining space on the screen, you can set its width to 0DP, and set Layout_weight to 1, all other controls do not set the weight property (principle: The system first allocates the space occupied by other controls, Because only the control that needs to be populated has the Layout_weight property, the rest of the space is allocated to it, and the control is filled with the goal of filling the remaining space on the screen.
Android Layout_weight Summary