表格布局模型以行列的形式管理子控件,每一行为一个TableRow的对象,当然也可以是一个View的对象。TableRow可以添加子控件,每添加一个为一列。
  android:layout_colum官方解释:The index of the column in which this child should be,也即是设置该控件在TableRow中所处的列。
  android:layout_span官方解释:Defines how many columns this child should span,也即是设置该控件所跨越的列数。
  android:collapseColumns官方解释:The 0 based index of the columns to collapse. The column indices must be separated by a comma: 1, 2, 5.也即是将TableLayout里面指定的列隐藏,若有多列需要隐藏,请用逗号将需要隐藏的列序号隔开。
  android:stretchColumns官方解释:The 0 based index of the columns to stretch. The column indices must be separated by a comma: 1, 2, 5. You can stretch all columns by using the value "*" instead. Note that a column can be marked stretchable and shrinkable at the same time.也即是设置指定的列为可伸展的列,可伸展的列会尽量伸展以填满所有可用的空间,若有多列需要设置为可伸展,请用逗号将需要伸展的列序号隔开。
  android:shrinkColumns官方解释:The 0 based index of the columns to shrink. The column indices must be separated by a comma: 1, 2, 5. You can shrink all columns by using the value "*" instead. 设置指定的列为可收缩的列。当可收缩的列太宽以至于让其他列显示不全时,会纵向延伸空间。当需要设置多列为可收缩时,将列序号用逗号隔开。
  下面用一个例子简单说明TableLayout的用法:
  
  http://schemas.android.com/apk/res/Android"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent"
  android:stretchColumns="1">
  
  <TEXTVIEW
  android:layout_column="1"
  android:text="打开..."
  android:padding="3dip" />
  <TEXTVIEW
  android:text="Ctrl-O"
  android:gravity="right"
  android:padding="3dip" />
  
  
  <TEXTVIEW
  android:layout_column="1"
  android:text="保存..."
  android:padding="3dip" />
  <TEXTVIEW
  android:text="Ctrl-S"
  android:gravity="right"
  android:padding="3dip" />
  
  
  <TEXTVIEW
  android:layout_column="1"
  android:text="另存为..."
  android:padding="3dip" />
  <TEXTVIEW
  android:text="Ctrl-Shift-S"
  android:gravity="right"
  android:padding="3dip" />
  
  <VIEW
  android:layout_height="2dip"
  android:background="#FF909090" />
  
  <TEXTVIEW
  android:text="*"
  android:padding="3dip" />
  <TEXTVIEW
  android:text="导入..."
  android:padding="3dip" />
  
  
  <TEXTVIEW
  android:text="*"
  android:padding="3dip" />
  <TEXTVIEW
  android:text="导出..."
  android:padding="3dip" />
  <TEXTVIEW
  android:text="Ctrl-E"
  android:gravity="right"
  android:padding="3dip" />
  
  <VIEW
  android:layout_height="2dip"
  android:background="#FF909090" />
  
  <TEXTVIEW
  android:layout_column="1"
  android:text="退出"
  android:padding="3dip" />
  
  
  对应的模拟器效果图如下所示:


  从效果图可以看出,该布局总共有三列,第一个TableRow里面的控件,从第1列开始布局。如果去掉所有控件的属性” android:layout_column="1"”,显示效果如下所示(总共3列,也即第0、1、2列,每一列都用虚线框标示):


  另外一个例子
  布局文件如下所示:
  
  http://schemas.android.com/apk/res/Android"
  android:orientation="vertical"
  android:layout_width="fill_parent"
  android:layout_height="wrap_content"
  >
  <TABLELAYOUT
  android:layout_width="fill_parent"
  android:layout_height="wrap_content"
  android:collapseColumns="1" >
  <TEXTVIEW
  android:text="表一"
  android:gravity="center"
  />
  
  <TEXTVIEW
  android:text="列0"
  android:background="@drawable/dot"/>
  <TEXTVIEW
  android:text="列1"
  android:background="@drawable/dot"/>
  
  
  <TABLELAYOUT
  android:layout_width="fill_parent"
  android:layout_height="wrap_content"
  android:stretchColumns="1">  将列序号用逗号隔开,例如:android:stretchColumns=“0,1”-->
  <TEXTVIEW
  android:text="表二"
  android:gravity="center" />
  
  <TEXTVIEW
  android:text="列0不能伸展"
  android:background="@drawable/dot"/>
  <TEXTVIEW
  android:text="列1可以伸展"
  android:gravity="right"
  android:background="@drawable/dot"/>
  
  
  <TABLELAYOUT
  android:layout_width="fill_parent"
  android:layout_height="wrap_content" >
  <TEXTVIEW
  android:text="表三"
  android:gravity="center" />
  
  <TEXTVIEW
  android:text="这一列很长,将会造成下一列无法显示或显示不全"
  android:background="@drawable/dot" />
  <TEXTVIEW
  android:text="这一列被挤到了屏幕外"
  android:background="@drawable/dot"/>
  
  
  <TABLELAYOUT
  android:layout_width="fill_parent"
  android:layout_height="wrap_content"
  android:shrinkColumns="0">  当需要设置多列为可收缩时,将列序号用逗号隔开,例如:android:shrinkColumns=“0,1”-->
  <TEXTVIEW
  android:text="表四"
  android:gravity="center"
  />
  
  <TEXTVIEW
  android:text="由于设置成了可收缩,所以这一列不管有多长都不会把其他列挤出去"
  android:background="@drawable/dot" />
  <TEXTVIEW
  android:text="这一列会被显示完全"
  android:background="@drawable/dot" />
  
  
  
  对应的模拟器效果图如下所示:


  布局分析:最外层用了一个垂直的linearLayout来放置里面的4个TableLayout,每个TableLayout由两行构成,分别是一个TextView和一个TableRow,每一个TableRow都由两个TextView组成了两列。

更多相关文章

  1. Android实现购物车加减器控件
  2. android控件详解----TextView
  3. android 自定义控件之一
  4. Google SwipeRefreshLayout(Goolge官方下拉刷新控件)尝鲜
  5. 控件布局
  6. 关于Android设置控件margin无效的解决办法
  7. 关于android的imagebutton,imageview等无文本控件警告的解决办法

随机推荐

  1. Android(安卓)USB挂载
  2. Android(安卓)异步任务加载图片代码
  3. 安卓Android大量项目源码实例
  4. 【Fragment】 Android(安卓)Fragment生命
  5. MAC上使用maven打android的包,报错:No And
  6. 【翻译】(8-补丁1)Android接口定义语言(AI
  7. Android_布局属性大全
  8. 阅读《Android(安卓)从入门到精通》(31)—
  9. Android应用程序键盘(Keyboard)消息处理机
  10. FregServer进程,获取ServiceManager代理对