android:stretchColumns
The zero-based index of the columns to stretch. The column indices must be separated by a comma: 1, 2, 5. Illegal and duplicate indices are ignored. You can stretch all columns by using the value "*" instead. Note that a column can be marked stretchable and shrinkable at the same time.
android:shrinkColumns
The zero-based index of the columns to shrink. The column indices must be separated by a comma: 1, 2, 5. Illegal and duplicate indices are ignored. You can shrink all columns by using the value "*" instead. Note that a column can be marked stretchable and shrinkable at the same time.
android:collapseColumns
The zero-based index of the columns to collapse. The column indices must be separated by a comma: 1, 2, 5. Illegal and duplicate indices are ignored.
<TableLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:stretchColumns="*"
android:background="@color/grey">
<TableRow>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="0"
android:background="@color/red"
android:textColor="@android:color/white"
android:textSize="30dp"
android:text="1" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="1"
android:textColor="@android:color/white"
android:textSize="30dp"
android:background="@color/green"
android:text="2" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="2"
android:textColor="@android:color/white"
android:textSize="30dp"
android:background="@color/blue"
android:text="3" />
</TableRow>
<TableRow>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="0"
android:background="@color/red"
android:textColor="@android:color/white"
android:textSize="30dp"
android:text="1" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="1"
android:textColor="@android:color/white"
android:textSize="30dp"
android:background="@color/green"
android:text="2" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="2"
android:textColor="@android:color/white"
android:textSize="30dp"
android:background="@color/blue"
android:text="3" />
</TableRow>
</TableLayout>
Explanations:
android:stretchColumns="*"
![enter image description here](https://istack.dev59.com/TkbsR.webp)
这意味着它会根据表格布局的宽度等比例地拉伸所有列
android:shrinkColumns="*"
![enter image description here](https://istack.dev59.com/mQIZ2.webp)
这意味着它会缩小所有列。
android:shrinkColumns="0,2"
android:stretchColumns="1"
![enter image description here](https://istack.dev59.com/jBCoe.webp)
意味着第0列和第2列是包含内容的,第1列会根据可用宽度进行拉伸
android:stretchColumns="0,1,2"
android:shrinkColumns="1"
![enter image description here](https://istack.dev59.com/TkbsR.webp)
如果列已经被拉伸,则不适用收缩
android:shrinkColumns="*"
android:collapseColumns="1"
![enter image description here](https://istack.dev59.com/9iJ2s.webp)
android:collapseColumns表示隐藏指定列
android:stretchColumns="*"
TextView:- android:layout_column="2"
![enter image description here](https://istack.dev59.com/55qoS.webp)
如果表格行的第一列布局参数不以0开头,则会将空视图添加到该行。
android:stretchColumns="*"
android:collapseColumns="1"
TextView:- android:layout_column="2"
![enter image description here](https://istack.dev59.com/7xASu.webp)
如果表格行的第一列布局参数不以0开始,则会向行中添加空视图,但如果您折叠列,则添加的空视图不会隐藏该列索引,只有显式视图才会隐藏添加的视图。
我希望这能帮到你。