android学习笔记19--------------tablelayout的均分效果

转载请注明出处:http://blog.csdn.net/yf210yf

TableLayout,表格布局采用行列形式管理UI组件,TableLayout不需要明确地声明有多少行和列,而是通过添加TableRow、其它组件来控制表格的行数、列数。
每次向TableLayout添加一个TableRow,就是在向表格添加一行,TableRow也是容器,可以向TableRow中添加组件,每添加一个组件,即是添加一列。
如果直接向TableLayout添加组件,则认为这个组件占用一行。
表格布局中列的宽度即是每一列中最宽的组件的宽度。 
使用前:

使用后:

 <TableLayout 
    	android:id="@+id/tableLayout1" 
    	android:layout_width="match_parent" 
    	android:layout_height="wrap_content"
    	android:stretchColumns="*" >
        <TableRow 
        	android:id="@+id/tableRow1" 
        	android:layout_width="wrap_content" 
        	android:layout_height="wrap_content">       
            <Button 
            	android:text="最近联系人" 
            	android:id="@+id/button4" 
            	android:layout_width="1dip" 
            	android:layout_height="wrap_content"></Button>   
            	
           	 <Button 
               	android:text="联系人" 
               	android:id="@+id/button5" 
               	android:layout_width="1dip" 
               	android:layout_height="wrap_content"></Button> 
               	
              <Button 
               	android:text="分组" 
               	android:id="@+id/button5" 
               	android:layout_width="1dip" 
               	android:layout_height="wrap_content"></Button>  
               	      
            </TableRow>
       
     
    </TableLayout>

TableLayout 增加一个属性 android:stretchColumns="*" 表示所有列都要自动拉伸,以便适应屏幕宽度。

它的值即可以是数字,也可以是*,注意数字是从0开始的,即:android:stretchColumns="1" 是设置 TableLayout所有行的第二列为扩展列。

上面我们会看到 第1列的按钮比其他列的按钮要宽,如果我们想都一样宽如何办呢?

一个简单办法:

android:layout_width="1dip"


评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值