TableLayout (2)

本文详细介绍了Android中TableLayout的使用方法及其属性设置,包括如何通过android:shrinkColumns使列内容适应屏幕大小、通过android:collapseColumns隐藏指定列以及通过android:stretchColumns实现列的拉伸。

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

Android开发文档    2010 
作者: craining   (曲阜师范大学)  个人主页: http://craining.blog.163.com/  邮箱: craining@163.com  46
android:stretchColumns="0,1">  缩减与延伸-->  
    <TableRow><!-- row1 -->  
    <Button android:id="@+id/button1"  
            android:layout_width="wrap_content"  
            android:layout_height="wrap_content"             
            android:text="Hello, I am a Button1"  
            android:layout_column="0"  
            />  
       <Button android:id="@+id/button2"  
     android:layout_width="wrap_content"  
     android:layout_height="wrap_content"  
     android:text="Hello, I am a Button2"  
     android:layout_column="1"  
     />  
     </TableRow>  
    <TableRow><!-- row2 -->  
    <Button android:id="@+id/button3"  
            android:layout_width="wrap_content"  
            android:layout_height="wrap_content"             
            android:text="Hello, I am a Button3"  
            android:layout_column="1"  
            />  
<Button android:id="@+id/button4"  
     android:layout_width="wrap_content"  
     android:layout_height="wrap_content"  
     android:text="Hello, I am a Button4"  
     android:layout_column="1"  
     />  
</TableRow>  
<TableRow>     
     <Button android:id="@+id/button5"  
     android:layout_width="wrap_content"  
     android:layout_height="wrap_content"  
     android:text="Hello, I am a Button5"  
     android:layout_column="2"  
     />  
</TableRow>  
</TableLayout> Table Layout(三) 
表格布局:是一个ViewGroup以表格显示它的子视图(view)元素,即行和列标识一个视图的
位置。其实Android的表格布局跟HTML中的表格布局非常类似,TableRow 就像HTML表格
的<tr>标记。 
用表格布局需要知道以下几点: 
  android:shrinkColumns,对应的方法:setShrinkAllColumns(boolean),作用:设
置表格的列是否收缩(列编号从 0 开始,下同),多列用逗号隔开(下同),如android:s
hrinkColumns="0,1,2",即表格的第 1、2、3 列的内容是收缩的以适合屏幕,不会挤出屏
幕。  
  android:collapseColumns,对应的方法:setColumnCollapsed(int,boolean),作用:
设置表格的列是否隐藏  
  android:stretchColumns,对应的方法:setStretchAllColumns(boolean),作用:设
置表格的列是否拉伸 
看下面的 res/layour/main.xml:  
 
<?xml version="1.0" encoding="utf-8"?>  
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"  
              android:layout_width="fill_parent"  
              android:layout_height="fill_parent"  
              android:shrinkColumns="0,1,2"><!-- have an eye on !   
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值