When using LinearLayout, the child controls can set the Layout_weight. The role of Layout_weight is to set the importance of the subspace in LinearLayout (the size of the control). The lower the value of the layout_weight, the more important the control is. If you do not set Layout_weight, the default weighting is 0.
If you place two Button,button1 and Button2,button1 Layout_weight in a linearlayout set to 1,button2 layout_weight setting to 2, And the layout_width of the two button are set to Fill_parent.
<linearlayout xmlns:android= "Http://schemas.android.com/apk/res/android"
Android:layout_width= "Match_parent"
android:layout_height= "Wrap_content"
android:orientation= "Horizontal" >
<button
Android:layout_width= "Fill_parent"
android:layout_height= "Wrap_content"
android:layout_weight= "1"
android:text= "Button1"/>
<button
Android:layout_width= "Fill_parent"
android:layout_height= "Wrap_content"
Android:layout_weight= "2"
android:text= "Button2"/>
</LinearLayout>
The Button1 occupies two-thirds of the screen width, while Button2 occupies One-third, as shown in:
If the layout_width of the two button are set to Wrap_content, the situation is reversed. Button1 accounted for One-third and Button2 accounted for Two-thirds as shown:
Ayout_weight is useful when designing complex layouts with linearlayout, for example, in a horizontal linear layout where you have enough space for control 1, and the rest of the space is assigned to control 2, as long as you set the layout_ of control 1 Width is set to wrap_content without setting layout_weight, whereas in control 2, setting Layout_width to Fill_parent,layout_weight is 1 .
This article goes from http://www.jb51.net/article/38560.htm, thanks to the author for sharing
How to use Android:layout_weight in Android