表格布局
表格布局就是以行列的形式来管理布局管理器中的组件,使组件以特定的行列排列
表格布局用TableLayout标记定义,在表格布局中,用TableRow来标记,每个TableRow占用一行
TableLayout支持的属性
| 属性 | 作用 |
|---|---|
| android:collapseColums | 设置需要被隐藏的列序号(序号从0开始),多个列序号之间用逗号隔开 |
| android:shrinkColums | 设置允许被收缩的列的列序号(序号哦才能够0开始),多个列序号之间用逗号隔开 |
| android:stretchColums | 设置允许被拉伸的序列号(序号从0开始), 多个列序号之间用逗号隔开 |
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:padding="20dp"
android:weightSum="15">
<TableRow
android:id="@+id/tableRow1"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="1"
android:padding="6dp">
<TextView/>
<TextView
android:text="用户名"
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:background="@color/colorPrimary"
android:textSize="24sp"/>
<EditText
android:id="@+id/editText1"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:textSize="24sp"
android:minWidth="200dp"/>
</TableRow>
<TableRow
android:id="@+id/tableRow2"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="1"
android:padding="6dp">
<TextView/>
<TextView
android:text="密码"
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:background="@color/colorPrimary"
android:textSize="24sp"/>
<EditText
android:id="@+id/editText2"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:textSize="24sp"
android:minWidth="200dp"
android:inputType="textPassword"/>
</TableRow>
<TableRow
android:id="@+id/tableRow3"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="1"
android:padding="10dp">
<TextView/>
<Button
android:text="登录"
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:background="@color/colorAccent"
android:textSize="24sp"/>
<Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="退出"
android:background="@color/colorAccent"
android:textSize="24sp"
android:minWidth="200dp"/>
</TableRow>
</TableLayout>

本文详细介绍了Android中的表格布局(TableLayout)概念及其使用方法。表格布局通过TableRow元素定义每一行,支持多列显示,适用于创建表格形式的UI界面。文章还解释了TableLayout的常见属性,如collapseColumns、shrinkColumns和stretchColumns,以及如何通过XML代码实现具体的布局效果。

2841

被折叠的 条评论
为什么被折叠?



