下列选项中,用于设置TableLayout布局中控件显示的位置的属性是()。 A.android:layout column B.android:layout span C.android:shrinkColumns D.以上都不是
时间: 2024-04-23 08:23:59 浏览: 46
答案是A.android:layout_column。TableLayout是Android中常用的布局容器,可以用于以表格形式显示多个控件。在TableLayout布局中,每个TableRow表示一行,每个控件表示一个单元格。android:layout_column属性用于设置控件在当前行中的列位置,其值为一个整数,表示当前控件所在的列索引,从0开始。例如,如果要将一个控件放在第2列,可以将android:layout_column属性的值设置为1。android:layout_span属性用于设置控件跨越的列数,其值为一个整数,表示控件占据的列数。android:shrinkColumns属性用于设置TableLayout布局中哪些列可以收缩以适应屏幕大小,其值为一个以逗号分隔的列索引列表。
相关问题
TableLayout布局中,设置了android:showDividers="middle"后, 还是不显示横线竖线 分隔线
在使用TableLayout布局时,设置了android:showDividers="middle"后,需要再设置分隔线的颜色和宽度,才能显示出横线竖线的分隔线。可以通过以下方式设置:
1. 设置横线分隔线的颜色和宽度:
```
tableLayout.setDividerDrawable(new ColorDrawable(Color.BLACK));
tableLayout.setDividerPadding(10);
```
2. 设置竖线分隔线的颜色和宽度:
```
tableLayout.setShowDividers(LinearLayout.SHOW_DIVIDER_MIDDLE);
tableLayout.setDividerDrawable(new ColorDrawable(Color.BLACK));
tableLayout.setDividerPadding(10);
```
注意:设置分隔线的颜色和宽度需要在代码中进行,而不能在xml文件中设置。
android:layout_span 怎么使用
android:layout_span是一个用于表格布局中的属性,用于指定单元格跨越的列数。具体使用方法如下:
1. 在布局文件中创建一个表格布局,如下所示:
```
<TableLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TableRow>
<TextView
android:text="Name"
android:layout_column="1"/>
<TextView
android:text="Age"
android:layout_column="2"/>
<TextView
android:text="Gender"
android:layout_column="3"/>
</TableRow>
<TableRow>
<TextView
android:text="John"
android:layout_column="1"/>
<TextView
android:text="25"
android:layout_column="2"/>
<TextView
android:text="Male"
android:layout_column="3"/>
</TableRow>
<TableRow>
<TextView
android:text="Lisa"
android:layout_column="1"
android:layout_span="2"/>
<TextView
android:text="Female"
android:layout_column="3"/>
</TableRow>
</TableLayout>
```
2. 在需要跨越多列的单元格中,添加android:layout_span属性,指定跨越的列数。例如在第三行中,第一个单元格跨越了2列,可以使用android:layout_span="2",如下所示:
```
<TableRow>
<TextView
android:text="Lisa"
android:layout_column="1"
android:layout_span="2"/>
<TextView
android:text="Female"
android:layout_column="3"/>
</TableRow>
```
这样就可以实现单元格跨越多列的效果。
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)