Record the layout_weight attribute that you know now. It is not comprehensive, but correct!
Layout_weight indicates "weight". My understanding is to set a display size ratio for the component.
When layout_weight is set to a value, two cases may occur.
First, when the "layout_width" attribute of the component is "fill_parent", the smaller the value, the larger the component.
Type 2: When the "layout_width" attribute of the component is "wrap_content", the larger the value, the larger the component.
First case:
XML Code
<Linearlayout
Android: layout_weight = "1"
Android: layout_width = "fill_parent"
Android: layout_height = "wrap_content"
Android: Orientation = "horizontal"
Android: layout_marginleft = "10dp"
Android: layout_marginright = "10dp"
>
<Button
Android: Id = "@ + ID/btn_save"
Android: layout_width = "fill_parent"
Android: layout_height = "wrap_content"
Android: layout_weight = "1"
Android: text = "save"
/>
<Button
Android: Id = "@ + ID/btn_return"
Android: layout_width = "fill_parent"
Android: layout_height = "wrap_content"
Android: layout_weight = "4"
Android: text = "return"
/>
</Linearlayout>
Here, when the "save" button's layout_weight = 1, "Return" button's layout_weight = 4, layout_width = "fill_parent", the running effect is:
Case 2:
XML Code
<Linearlayout
Android: layout_weight = "1"
Android: layout_width = "fill_parent"
Android: layout_height = "wrap_content"
Android: Orientation = "horizontal"
Android: layout_marginleft = "10dp"
Android: layout_marginright = "10dp"
>
<Button
Android: Id = "@ + ID/btn_save"
Android: layout_width = "wrap_content"
Android: layout_height = "wrap_content"
Android: layout_weight = "1"
Android: text = "save"
/>
<Button
Android: Id = "@ + ID/btn_return"
Android: layout_width = "wrap_content"
Android: layout_height = "wrap_content"
Android: layout_weight = "4"
Android: text = "return"
/>
</Linearlayout>
Here, when the "save" button's layout_weight = 1, "Return" button's layout_weight = 4, layout_width = "wrap_content", the running effect is:
The above is my summary of the known situations. If any of them is incorrect or cannot be summarized, please kindly advise!
The author is carrying his bag and moving forward alone ...."