Android Studio 上需要包含列标题和不同列宽的列表
像这样:
Code Product Description Stock Tel P1234 Portland Cement 25kg 70 0208 1234567 P4321 MGM Sharp Sand Bulk Bag 800kg 3 0799 98765433
可变长度的产品描述最多可达 45 个字符。
为此,将在移动设备上使用更宽的水平显示。
我查了一下,发现gridview不支持不同宽度的列。 据我了解,列表视图可能是相同的。
有没有办法不使用 x,y 来定位列?
Like this:
Code Product Description Stock Tel P1234 Portland Cement 25kg 70 0208 1234567 P4321 MGM Sharp Sand Bulk Bag 800kg 3 0799 98765433
The variable-length product description may be up to 45 characters.
Will use the wider horizontal display on the mobile for this.
I checked and found gridview does not support different-width columns.
From what I understand it may be the same for listview.
Is there a way without using x,y for positioning the columns?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用
GridLayout
或 (可能)与TableLayout
。还有 GridView,但据我所知,GridView 中的每个单元格都必须具有相同的大小。我不知道一个单元格是否可以跨越 GridView 中的多个行/列,但即使可以,并且由于每个单元格的大小必须相同,那么您必须计算有多少个单元格每个条目都需要您的数据。所以我建议使用前两个选项。
最后,
RecyclerView
可以在网格中排列View
(通过GridLayoutManager
),但我不知道它是否可以满足您的要求(例如作为每个单元格的可变大小),所以我将其留在这里,以防您想将其视为另一个可能的选项。下面是一个使用
GridLayout
实现的示例:TextView
被添加到网格中,从左上角单元格开始向右直到4
code> 列已填充,在这种情况下,下一个TextView
将按照相同的模式进入后续行。此行为是由于水平方向(这是 GridLayout 的默认值)以及将列数设置为 4 的组合所致。默认情况下,每个单元格跨越一行和一列。GridLayout
没有内置的滚动支持,但您可以将其添加到HorizontalScrollView
和垂直ScrollView
中,如上面的示例代码,为了启用滚动。您始终可以在这些
ViewGroup
的文档中查看有关这些 ViewGroup 的更多信息。You can try this with a
GridLayout
or (possibly) with aTableLayout
.There is also
GridView
, but as far as I know every cell in aGridView
must have the same size with every other. I don't know if a cell could span multiple rows/columns in aGridView
though, but even if it can and since every cell must be the same size, then you would have to calculate how many cells your data would require for each entry. So I would suggest going with the previous 2 options.Finally,
RecyclerView
s can arrangeView
s in a grid (viaGridLayoutManager
), but I am not aware if it can fit your requirements (such as variable size for each cell), so I am just leaving it here in case you want to look at it as another possible option.Here is an example implementation with a
GridLayout
:The
TextView
s are added to the grid starting from the top-left cell and going to the right until4
columns are filled, in which case the nextTextView
s will go in subsequent rows following the same pattern. This behaviour is because of the combination of horizontal orientation (which is the default value for theGridLayout
), together with setting the column count to4
. By default, each cell spans a single row and a single column.The
GridLayout
does not have built in support for scrolling, but you can add it to both aHorizontalScrollView
and a verticalScrollView
, as demonstrated in the above sample code, in order to enable scrolling.You can always look more information about those
ViewGroup
s in their documentation.