什么是TableLayout

表格布局是一个ViewGroup以表格显示它的子视图(view)元素,即行和列标识一个视图的位置。Android的表格布局跟HTML中的表格布局非常类似,TableRow 就像HTML表格的<tr>标记。


TableLayout常用的属性
android:collapseColumns:隐藏指定的列
android:shrinkColumns:收缩指定的列以适合屏幕,不会挤出屏幕
android:stretchColumns:尽量把指定的列填充空白部分
android:layout_column:控件放在指定的列
android:layout_span:该控件所跨越的列数


下面通过一个简单的例子实现其中的几个属性

Android之TableLayout布局_第1张图片

先来分析一下:第一行的中间的按钮填充空白部分,第二行的第二个按钮放在右边列,第三行的第二个按钮横跨2列

代码如下

<TableLayout    xmlns:android="http://schemas.android.com/apk/res/android"    android:layout_width="match_parent"    android:layout_height="wrap_content"    android:stretchColumns="1" >    <TableRow        android:layout_width="wrap_content"        android:layout_height="wrap_content" >        <Button             android:text="Button11"/>        <Button             android:text="Button12"/>        <Button             android:text="Button13"/>    </TableRow>    <TableRow        android:layout_width="wrap_content"        android:layout_height="wrap_content" >        <Button             android:text="Button21"/>        <Button             android:layout_column="2"            android:text="Button23"/>    </TableRow>        <TableRow        android:layout_width="wrap_content"        android:layout_height="wrap_content" >        <Button             android:text="Button31"/>        <Button             android:layout_span="2"            android:text="Button33"/>    </TableRow></TableLayout>

OK,关于Android之TableLayout布局的介绍就到这了。


更多相关文章

  1. Android 布局之DrawLayout
  2. Android学习笔记_布局文件属性的说明
  3. (4.1.25)android学习之布局
  4. 布局初步
  5. Android布局及控件的属性说明
  6. android UI设计,android ui开发,android 页面设计,android页面布
  7. 安卓表格布局android:collapseColumns,android:shrinkColumns和s

随机推荐

  1. Android启动流程简析(一)
  2. android中.classpath和.project作用
  3. android 重命名文件
  4. Android中使用SVG与WebFont矢量图标
  5. android 自定义基于组件的注册用户对话框
  6. Android获取应用的签名信息
  7. 3. android 自动完成文本框
  8. android平板
  9. Android 监听手机GPS打开状态实现代码
  10. 自定义 Android(安卓)对话框 (AlertDialo