gpt4 book ai didi

android - 具有不同列数和自动列宽的表格

转载 作者:行者123 更新时间:2023-11-30 04:49:14 27 4
gpt4 key购买 nike

我想通过指定每行的列数来绘制表格/网格,并绘制一些不同颜色的单元格。一行应跨越整个屏幕。每行的列的列宽应该相同。我尝试将 TableLayout 与 View 或 Textviews 一起使用,但我无法弄清楚如何为每一行均匀分布列。

网格应如下所示:http://img148.imageshack.us/img148/4239/gridk.png

最佳答案

我不知道 TableLayout 是否真的是您要找的东西,因为不同行中的列没有对齐。

一般来说,如果你想在一行中添加一堆 View 并且让它们每个占用相同的空间量,你可以在每个 View 上设置 android:layout_weight = 1意见。

例如,对于单行:

<LinearLayout android:layout_width="FILL_PARENT" android:layout_height="WRAP_CONTENT" android:orientation="horizontal">
<TextView android:layout_weight="1"/>
<TextView android:layout_weight="1"/>
<TextView android:layout_weight="1"/>
<TextView android:layout_weight="1"/>
</LinearLayout>

对于多行,你可以使用 LinearLayoutandroid:orientation="vertical",或者你只能使用 TableLayout TableRow 中的一列。

关于android - 具有不同列数和自动列宽的表格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3981484/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com