TableRow平均布局单元格(转载)

本文介绍如何使用TableRow布局实现按钮等控件的平均分配显示,并通过设置android:layout_weight属性来调整不同控件间的比例。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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>

 
 
 
 
 

转载于:https://www.cnblogs.com/merryjd/archive/2012/11/29/2794905.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值