Layout_weight is used to assign importance values to multiple views in a linear layout.All views have a layout_weight value. The default value is 0, indicating that the value must be displayed.
The size of a view occupies the size of the screen space. If a value greater than zero is assigned, the parentThe available space in the image is separated. The split size depends on the layout_weight of each view.Value and the overall layout of the current screen, layout_weight value andThe percentage of the layout_weight value is determined.
For example:
For example, we have a text label and two text editing elements in the horizontal direction.
The text label does not specify the layout_weight value, so it occupies the minimum space required.
If the layout_weight value of each of the two text editing elements is set to 1, the two are equally divided into the remaining width of the parent view layout (because we declare that the importance of the two is equal ).
If two In the text editing element, the first value of layout_weight is set to 1, and the second value is set to 2. 1/3 of the remaining space is allocated to the second one. the second is given to the first one (the smaller the value, higher importance ).
<Linearlayout Android: Orientation = "horizontal" Android: layout_width = "fill_parent" Android: layout_height = "fill_parent" Android: layout_weight = "1"> <textview Android: layout_width = "wrap_content" Android: layout_height = "fill_parent" Android: layout_weight = "1" Android: Background = "# aa0000" Android: gravity = "center" Android: TEXT = "1"/> <textview Android: layout_width = "wrap_content" Android: layout_height = "fill_parent" Android: layout_weight = "2" Android: Background = "#00aa00" Android: gravity = "center" Android: text = "1"/> <textview Android: layout_width = "wrap_content" Android: layout_height = "fill_parent" Android: layout_weight = "3" Android: background = "# tianaa" Android: gravity = "center" Android: text = "1"/> </linearlayout>
The effect is as follows: