android的TableLayout布局界面元素填满整个屏幕

在Android界面设计中,使用TableLayout布局时,要使界面元素完全填充屏幕,需要设置TableLayout和TableRow的宽度及高度为fill_parent,并为TableRow添加layout_weight属性设为1。对于控件如Button,同样需要设置width、height为fill_parent和layout_weight为1,以确保横向上铺满屏幕。提供了一个完整的包含Button的TableLayout布局代码示例。
           在做android界面设计时如果使用到TableLayout布局即表格布局,要想让界面中的控件填满整个屏幕除了要设置TableLayout的属性
	android:layout_width="fill_parent"
    	android:layout_height="fill_parent"
还需要设置TableRow的属性为
	android:layout_width="fill_parent"
        	android:layout_height="fill_parent" 
        	android:layout_weight="1"
注意这里的android:layout_weight="1"一定不能忘了,否则子控件的android:layout_height="fill_parent"是不起作用的。
最后就是界面控件的属性了,这里以Button为例来做演示
<Button
            android:id="@+id/button1"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:layout_weight="1"
            android:text="Button" />

和上面的一样这里的android:layout_weight="1"也不能少,这个保证按钮能在横向上铺满屏幕。
完整的布局文件代码如下:
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    tools:context=".MainActivity" >
    <TableRow
        android:id="@+id/tableRow1"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent" 
        android:layout_weight="1">
        <Button
            android:id="@+id/button1"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:layout_weight="1"
            android:text="Button" />
    </TableRow>

</TableLayout>
效果如下:



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值