From today on, the reading time of the knowledge points to organize into a blog,
This is relatively simple and is expected to have experienced all used, weight properties
When doing the Android layout, you often encounter the need to proportionally allocate space for several controls
Example effect
Set two button at the bottom, occupy the bottom width part of the same time, maintain a ratio of 1:3,
Of course, such an ugly layout is not very useful, only to illustrate the use of weight
The layout code is as follows:
<linearlayout xmlns:android= "http://schemas.android.com/apk/res/android" xmlns:tools= "http// Schemas.android.com/tools " android:layout_width=" match_parent " android:layout_height=" Match_parent " android:weightsum= "6" android:gravity= "Bottom|center_horizontal" > <button android:id= "@ +id/bn_main_left " android:layout_width=" 0DP " android:layout_height=" wrap_content " android:layout_ weight= "1" android:text= "left"/> <button android:id= "@+id/bn_main_right" android: Layout_width= "0DP" android:layout_height= "wrap_content" android:layout_weight= "3" android:text= "Right"/></linearlayout>
Inside LinearLayout There is a weightsum, which is used to set the weight sum of linearlayout,
The Layout_weight in the button is used to set the size of the button's occupied linearlayout space.
Image a little said, linearlayout like a box, weightsum set the box size to 6,
Put two buttons in the box, set layout_weight= "1" to the left button, occupy 1/6 space,
Right button set layout_weight= "3", Occupy 3/6 space
So two buttons add up to occupy the 4/6 of LinearLayout,
Assuming that Weightsum is not set for LinearLayout, the total control layout_weight is assumed to be the sum of all controls.
jason0539
Weibo:http://weibo.com/2553717707
Blog:http://blog.csdn.net/jason0539(reprint please indicate the source)
Android uses the weight property to implement proportional allocation of space for controls