Layout_weight is used to assign values to the importance of many views in a linear layout.
All views have a layout_weight value, which defaults to zero, meaning it needs to be displayed
How large a view occupies is the screen space. If you assign a value higher than zero, the parent view
The available space in the graph is split, and the split size depends on the layout_weight of each view
Value and the overall layout_weight value of the value in the current screen layout and the other view screen cloth
Percentage of the Layout_weight value of the bureau.
For example, let's say we have a text label and two text editing elements in the horizontal direction.
The text label does not specify a layout_weight value, so it will occupy the minimum space needed to provide it.
If the layout_weight value of each of the two text-editing elements is set to 1, the two are split equally
The remaining width in the parent view layout (because we declare the importance of the two equal). If two X
The text editing element where the first Layout_weight value is set to 1, and the second is set to 2,
The remaining space of two-thirds points to the first, One-third points to the second (the smaller the value, the higher the importance).
See Example:
<?XML version= "1.0" encoding= "Utf-8"?> <LinearLayoutxmlns:android= "Http://schemas.android.com/apk/res/android"android:orientation= "vertical"Android:layout_width= "Fill_parent"Android:layout_height= "Fill_parent" > <LinearLayoutandroid:orientation= "Horizontal"Android:layout_width= "Fill_parent"Android:layout_height= "Fill_parent"Android:layout_weight= "1"> <TextViewAndroid:text= "Redwwwwwww"android:gravity= "Center_horizontal"Android:background= "#aa0000"Android:layout_width= "Wrap_content"Android:layout_height= "Fill_parent"Android:layout_weight= "1"/> <TextViewAndroid:text= "Green"android:gravity= "Center_horizontal"Android:background= "#00aa00"Android:layout_width= "Wrap_content"Android:layout_height= "Fill_parent"Android:layout_weight= "2"/> <TextViewAndroid:text= "Blue"android:gravity= "Center_horizontal"Android:background= "#0000aa"Android:layout_width= "Wrap_content"Android:layout_height= "Fill_parent"Android:layout_weight= "3"/> <TextViewAndroid:text= "Yellow"android:gravity= "Center_horizontal"Android:background= "#aaaa00"Android:layout_width= "Wrap_content"Android:layout_height= "Fill_parent"Android:layout_weight= "4"/> </LinearLayout> </LinearLayout>