Android TableLayout 用法详解
TableLayout 是 Android 中一种常用的布局容器,它以表格形式排列子视图,适合展示结构化数据或需要行列对齐的界面。以下是 TableLayout 的全面使用指南。
一、基本特性
- 表格结构:由行(TableRow)和单元格组成
- 灵活布局:支持跨行/跨列
- 自动对齐:默认左对齐,可通过属性调整
- 滚动支持:可嵌套 ScrollView 实现滚动效果
二、基本用法
1. 添加依赖
TableLayout 是 Android 基础控件,无需额外依赖。
2. XML 布局示例
<TableLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:stretchColumns="1" <!-- 第二列拉