TableLayout表格布局

发布于 2022-04-09  96 次阅读


TableLayout表格布局模型以行列的形式管理子控件,每一行为一个TableRow的对象, 当然也可以使一个View的对象

标签

TableRow:

全局变量

属性名变量类型说明
collapseColumns整型数字隐藏从0开始的索引列,列之间必须用逗号隔开1,2
shrinkColumns整型数字收缩从0开始的索引列,当可收缩的列太宽(内容太多时)不会被挤出屏幕,列之间 用逗号隔开1,2,你可以通过”*”代替收缩所有列,注意一列能同时表示收缩和拉伸
stretchColumns整型数字拉伸从0开始的索引列,以填满剩下的多余空白空间,列之间必须用逗号隔开,1,2, 你可以通过”*”代替收缩所有列,注意一列能同时表示收缩和拉伸

TableRow的子控件的主要属性:

属性名变量类型说明
layout_column整型数字该控件显示在第x列
layout_span整型数字该控件占据x列

实例:

<?xml version="1.0" encoding="utf-8"? 
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
 android:layout_width="match_parent" android:layout_height="match_parent"
 android:collapseColumns="0"
 android:shrinkColumns="4" 

 <TableRow
  android:id="@+id/tablerow1"
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"  

  <Button
   android:id="@+id/button4"
   android:layout_width="wrap_content"
   android:layout_height="wrap_content"
   android:text="Button1" / 

  <Button
   android:id="@+id/button5"
   android:layout_width="wrap_content"
   android:layout_height="wrap_content"
   android:text="Button2" / 

  <Button
   android:id="@+id/button6"
   android:layout_width="wrap_content"
   android:layout_height="wrap_content"
   android:text="Button3" / 

  <Button
   android:id="@+id/button7"
   android:layout_width="wrap_content"
   android:layout_height="wrap_content"
   android:text="Button4" / 

  <Button
   android:id="@+id/button8"
   android:layout_width="wrap_content"
   android:layout_height="wrap_content"
   android:text="Button555555555555555555555555" / 
 </TableRow 
</TableLayout 


谢谢你能看完呀~~~