表格布局TableLayout是Android中比較经常使用的一个布局控件,既然是表格,肯定有行和列,TableLayout中的行有TableRow组成。列依据每行控件的数量来确定

假如第一行有3个控件,第2行有4个控件,那么这个表格的列数就去最大列数,即4列。

               1.属性介绍

                表格有下面几个重要属性

                   android:shrinkColumns="2" 自己主动收缩的列。多个列用逗号隔开,自己主动收缩的意思是假设该列的内容超出了表格列的宽度,自己主动向下显示

                  android:stretchColumns="1" 自己主动伸缩列,多个列用逗号隔开。假设表格中全部列。都没有占满表格宽度,该列自己主动伸缩。

                   android:collapseColumns   隐藏指定的列,多个列用逗号隔开

                  android:layout_column="1" 用来设置该表格中控件所在的列数。

                 android:layout_span  用来设置表格中控件所占的列数

                      .Net程序猿玩转Android开发---(8)表格布局TableLayout


              2.商品列表演示样例

                  以下我们用TableLayout来完毕一个商品列表的布局

               .Net程序猿玩转Android开发---(8)表格布局TableLayout

> <TableLayout xmlns:andro android:layout_width="match_parent" android:layout_height="match_parent" > <TableRow android: android:layout_width="fill_parent" android:layout_height="wrap_content" > <TableLayout android:layout_width="match_parent" android:layout_height="match_parent" > <TableRow android:layout_width="fill_parent" android:layout_height="wrap_content" > <ImageView android:layout_width="100dp" android:layout_height="100dp" android:src="@raw/pad" /> </TableRow> </TableLayout> <TableLayout android:layout_width="match_parent" android:layout_height="match_parent" > <TableRow android:layout_width="fill_parent" android:layout_height="wrap_content" > <TableLayout android:layout_width="match_parent" android:layout_height="fill_parent" > <TableRow android:layout_height="match_parent" > <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="商品名称:IPAD AIR" android:layout_margin="10dp" /> </TableRow> <TableRow android:layout_height="match_parent" > <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="商品价格:$99" android:layout_margin="10dp" /> </TableRow> <TableRow android:layout_height="match_parent" > <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="商品颜色:白色" android:layout_margin="10dp" /> </TableRow> </TableLayout> </TableRow> </TableLayout> </TableRow> <TableRow android: android:layout_width="fill_parent" android:layout_height="5dp" android:background="#EEE8CD" > <TextView android:layout_width="fill_parent" android:layout_height="3dp" android:background="#EEE8CD" /> </TableRow> <TableRow android: android:layout_width="fill_parent" android:layout_height="wrap_content" > <TableLayout android:layout_width="match_parent" android:layout_height="match_parent" > <TableRow android:layout_width="fill_parent" android:layout_height="wrap_content" > <ImageView android:layout_width="100dp" android:layout_height="100dp" android:src="@raw/pad" /> </TableRow> </TableLayout> <TableLayout android:layout_width="match_parent" android:layout_height="match_parent" > <TableRow android:layout_width="fill_parent" android:layout_height="wrap_content" > <TableLayout android:layout_width="match_parent" android:layout_height="fill_parent" > <TableRow android:layout_height="match_parent" > <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="商品名称:IPAD AIR" android:layout_margin="10dp" /> </TableRow> <TableRow android:layout_height="match_parent" > <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="商品价格:$99" android:layout_margin="10dp" /> </TableRow> <TableRow android:layout_height="match_parent" > <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="商品颜色:白色" android:layout_margin="10dp" /> </TableRow> </TableLayout> </TableRow> </TableLayout> </TableRow> <TableRow android: android:layout_width="fill_parent" android:layout_height="5dp" android:background="#EEE8CD" > <TextView android:layout_width="fill_parent" android:layout_height="3dp" android:background="#EEE8CD" /> </TableRow> <TableRow android: android:layout_width="fill_parent" android:layout_height="wrap_content" > <TableLayout android:layout_width="match_parent" android:layout_height="match_parent" > <TableRow android:layout_width="fill_parent" android:layout_height="wrap_content" > <ImageView android:layout_width="100dp" android:layout_height="100dp" android:src="@raw/pad" /> </TableRow> </TableLayout> <TableLayout android:layout_width="match_parent" android:layout_height="match_parent" > <TableRow android:layout_width="fill_parent" android:layout_height="wrap_content" > <TableLayout android:layout_width="match_parent" android:layout_height="fill_parent" > <TableRow android:layout_height="match_parent" > <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="商品名称:IPAD AIR" android:layout_margin="10dp" /> </TableRow> <TableRow android:layout_height="match_parent" > <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="商品价格:$99" android:layout_margin="10dp" /> </TableRow> <TableRow android:layout_height="match_parent" > <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="商品颜色:白色" android:layout_margin="10dp" /> </TableRow> </TableLayout> </TableRow> </TableLayout> </TableRow> <TableRow android: android:layout_width="fill_parent" android:layout_height="5dp" android:background="#EEE8CD" > <TextView android:layout_width="fill_parent" android:layout_height="3dp" android:background="#EEE8CD" /> </TableRow> </TableLayout>





相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-02-09
  • 2021-05-07
  • 2021-06-17
  • 2022-12-23
  • 2021-09-10
猜你喜欢
  • 2022-12-23
  • 2022-02-06
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-10-29
  • 2022-12-23
相关资源
相似解决方案