Android Development screen adaptation can not be separated from the Weight attribute, this property is only applicable to the linearlayout, the common way to use:
1.<? XML version= "1.0" encoding="Utf-8" ?>
< Span style= "Font-family:consolas;color: #3F7F7F" > linearlayout &NBSP; = " Http://schemas.android.com/apk/res/android "
android:layout_width= "Match_parent"
android:layout_height= "Match_parent"
android:orientation= "Horizental"
android:background= "@color/white"
>
<button
Android:width= "0DP"
android:height= "Wrap_content"
Android:weight= "1.0"
android:text= "Button1"
/>
<button
Android:width= "0DP"
android:height= "Wrap_content"
Android:weight= "2.0"
android:text= "Button1"
/>
</LinearLayout>
The above definition is in the form of setting the width or height to be proportional to 0DP and then setting the proportion of space in weight
The final display style is the same as the proportions we designed.
However, we often encounter the following situations:
<? XML version= "1.0" encoding="Utf-8" ?>
< Span style= "Font-family:consolas;color: #3F7F7F" > linearlayout &NBSP; = " Http://schemas.android.com/apk/res/android "
android:layout_width= "Match_parent"
android:layout_height= "Match_parent"
android:orientation= "Horizental"
android:background= "@color/white"
>
<button
Android:width= "Match_parent"
android:height= "Wrap_content"
Android:weight= "1.0"
android:text= "Button1"
/>
<button
Android:width= "Match_parent"
android:height= "Wrap_content"
Android:weight= "2.0"
android:text= "Button1"
/>
</LinearLayout>
The above definition is in the form of setting the proportion of the space size that needs to be prorated for match_parent and then set in weight
The final display of the style, as we designed the proportions of the opposite.
What is this for?
Now specify the width of the entire UI layout is x, the above two methods are temporarily called: Mode 1, Mode 2;
Paradigm:
Calculated width = width of original width + remaining space%
Mode 1:
Because of its display, as our proportions are set to be the same, so the calculated width is 1/3 x
The original width is defined as 0DP,
Because the width of both btn1 and BTN2 is 0DP, the remaining space is X
btn1:1/3x = 0+ X*1/3
btn2:2/3x = 0+X*2/3
Mode 2:
Because its width is match_parent, so its original breadth is x;
Because two btn are placed, their widths are match_parent, so the total width of the two buttons is 2x, so the width of the remaining space is x-2x;
btn1:2/3x = x+ (x-2x) *1/3
btn2:1/3x = x+ (x-2x) *2/3
Thanks to the great God of the network, learn a lot
Android Weight Use detailed