TableLayout (2)

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 !   
posted @ 2012-10-30 13:35  sfshine  阅读(143)  评论(0编辑  收藏  举报