比如:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 |
<LinearLayout android:layout_width= "match_parent" android:layout_height= "wrap_content" android:orientation= "horizontal" android:layout_marginTop= "10dip" style= "?android:attr/buttonBarStyle" > <Button style= "?android:attr/buttonBarButtonStyle" android:id= "@+id/uploadpb" android:layout_weight= "1" android:layout_width= "10dip" android:layout_height= "wrap_content" android:text= "@string/uploadpb"
/> <Button style= "?android:attr/buttonBarButtonStyle" android:id= "@+id/downloadpb" android:layout_weight= "1" android:layout_width= "10dip" android:layout_height= "wrap_content" android:text= "@string/downloadpb" /> </LinearLayout> |
在这个水平布局的线性布局中,我给每个按钮任意一个layout_width(否则编译时会报错),给每个按钮一个「android:layout_weight="1"」,这样就均等分配了水平空间,like this:
用layout_weight是为了适应不同android设备的不同屏幕分辨率。
原文:http://www.cnblogs.com/larrylawrence/p/3518449.html