gpt4 book ai didi

Cannot get borders to display properly in android GridView(无法在Android GridView中正确显示边框)

转载 作者:bug小助手 更新时间:2023-10-28 22:22:38 26 4
gpt4 key购买 nike



Despite extensive research here, I cannot find a way to get uniform grid lines in an Android GridView. In my case, every cell in the GridView contains a single TextView object.

尽管我在这里进行了广泛的研究,但我找不到一种方法在Android GridView中获得统一的网格线。在我的例子中,GridView中的每个单元格都包含一个TextView对象。


Two methods I have found suggested are 1) set the GridView's background to one colour, have a small margin and set all the TextViews' borders to a different colour or 2) create a rectangular border drawable resource and make this the background for the TextViews.

我发现建议的两种方法是:1)将GridView的背景设置为一种颜色,设置较小的边距,并将所有TextView的边框设置为不同的颜色;或者2)创建一个矩形边框可绘制资源,并将其作为TextView的背景。


Both these methods hit the same problem. If one TextView is narrower than others in the same column then with method 1, I get huge borders filling all available space in the cell. With option 2, I get a tiny little border that only just encloses the text.

这两种方法都遇到了同样的问题。如果一个TextView比同一列中的其他TextView更窄,那么使用方法1,我会得到巨大的边框,填充单元格中的所有可用空间。使用选项2,我得到了一个仅包含文本的很小的边框。


I presume I need a way to ensure each TextView fills the entire column width (or enclose it in a container that does). Any suggestions?

我假设我需要一种方法来确保每个TextView填充整个列宽(或者将其包含在一个容器中)。有什么建议吗?


I must say that I'm amazed how hard it is to draw a simple grid with border lines. I've been experimenting for half a day without success. Clearly, I am missing something obvious?

我必须说,我很惊讶用边界线绘制一个简单的网格是多么的困难。我已经试验了半天,但没有成功。显然,我漏掉了一些明显的东西?


更多回答
优秀答案推荐

I think I have found an answer. If I set both layout_gravity = "fill_horizontal" and gravity = "center", I get almost what I want. Only almost because the final problem is that now the lines between the cells are twice the weight of the outside border around the whole thing. I presume this is because I am (for example) getting both the right border of one cell and the left border of the adjacent one. I can think of some ways around that but, for now, it will have to do. I am still gobsmacked that such a simple, and presumably common requirement, is so difficult to achieve.

我想我已经找到了答案。如果我同时设置Layout_Graight=“Fill_Horizular”和Grasion=“Center”,我几乎可以得到我想要的东西。几乎是因为最后的问题是,现在细胞之间的线条是围绕整个物体的外部边界的两倍。我假设这是因为(例如)我同时获得了一个单元格的右边框和相邻单元格的左边框。我可以想出一些办法来解决这个问题,但就目前而言,只能这样了。这样一个简单的、想必也是普遍的要求,却如此难以实现,我至今仍大吃一惊。


更多回答

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