android布局常常用到平均分配布局控件,比如用户登录的界面中登录与注册两个按钮,需要按1:1的比例平均分配到布局内容中,TableRow布局可以实现这样的效果。如图-1。需要设置android:layout_weight的权重。如果两个按钮均为android:layout_weight=”1″,则可以设置TableRow的比例为1:1,如果Login按钮设置android:layout_weight=”1″,Register按钮设置android:layout_weight=”2″,则Login按钮在TableRow布局中的比例为1:3,Register按钮在TableRow布局中的比例为2:3。

xml文件如下:

<LinearLayout xmlns:android=”http://schemas.android.com/apk/res/android” android:layout_width=”fill_parent” android:layout_height=”fill_parent” android:padding=”12dip”>

<TableRow android:layout_width=”fill_parent” android:layout_height=”wrap_content”> <Button android:layout_height=”fill_parent” android:layout_width=”fill_parent” android:text=”Login”  android:id=”@+id/loginBtn” android:layout_weight=”1″></Button> <Button android:layout_height=”fill_parent” android:layout_width=”fill_parent” android:text=”Register”  android:id=”@+id/registerBtn” android:layout_weight=”1″></Button> </TableRow>

</LinearLayout>

 
 
 
 
 
posted on 2012-11-29 16:33  merryjd  阅读(792)  评论(0编辑  收藏  举报