我是安卓开发新手。我正在阅读TableLayout,它具有三个主要属性
android:stretchColumns,
android:collapseColumns 和 android:shrinkColumns。
经过一些研究,我明白了 android:stretchColumns 的确切含义,但我对折叠列和收缩列感到困惑。官方文档说。
android:收缩列
要收缩的列的从零开始的索引。列索引必须用逗号分隔:1, 2, 5。非法和重复的索引将被忽略。您可以使用值“*”来缩小所有列。请注意,列可以同时标记为可拉伸和可收缩。
android:collapseColumns
要折叠的列的从零开始的索引。列索引必须用逗号分隔:1, 2, 5。非法和重复的索引将被忽略。
到底是什么意思shrink and collapse.谁能告诉我它们之间有什么区别?
-
android:stretchColumns
要拉伸的列的从零开始的索引。列索引必须用逗号分隔:1, 2, 5。非法和重复的索引将被忽略。您可以使用值“*”来拉伸所有列。请注意,列可以同时标记为可拉伸和可收缩。
-
android:收缩列
要收缩的列的从零开始的索引。列索引必须用逗号分隔:1, 2, 5。非法和重复的索引将被忽略。您可以使用值“*”来缩小所有列。请注意,列可以同时标记为可拉伸和可收缩。
-
android:collapseColumns
要折叠的列的从零开始的索引。列索引必须用逗号分隔:1, 2, 5。非法和重复的索引将被忽略。
<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="0" />
<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="1" />
<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="2" />
</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="0" />
<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="1" />
<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="2" />
</TableRow>
</TableLayout>
说明:
android:stretchColumns="*"
意味着它根据表格布局宽度均匀拉伸所有列
android:shrinkColumns="*"
意味着它缩小所有列
android:shrinkColumns="0,2"
android:stretchColumns="1"
意味着第 0 列和第 2 列是换行包含,第 1 列拉伸到可用宽度
android:stretchColumns="0,1,2"
android:shrinkColumns="1"
意味着如果列已经拉伸则收缩不适用
android:shrinkColumns="*"
android:collapseColumns="1"
android:collapseColumns 意味着它隐藏给定的列
android:stretchColumns="*"
TextView :- android:layout_column="2"
表行第一列布局参数的含义不以 0 开头,然后将空视图添加到行中
android:stretchColumns="*"
android:collapseColumns="1"
TextView :- android:layout_column="2"
意味着如果 tablerow 第一列布局参数不以 0 开头,则将空视图添加到行中,但如果折叠列,则添加空视图不会隐藏该列索引,仅通过显式视图隐藏添加的视图
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)