Android GridView 绘制分隔线
我想知道在 GridView 中的项目(当前是文本视图)之间绘制分隔线的最简单方法。我能想到的唯一方法是在这些文本视图周围绘制边框,这样当组合起来时,它们看起来就像连续的水平和垂直分隔线。
列表视图有 setDivider() 但网格视图没有?
谢谢。
I'd like to know the simplest way to draw dividers between items (currently textviews) within a GridView. The only way I can think of is to draw borders around those textviews so when combined, they look like continuous horizontal and vertical dividers.
There is a setDivider() for listviews but not gridviews?
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您只想要简单的线条作为边框,则为 GridView 设置背景颜色和适当的填充和填充要简单得多。间距:
In case you want just simple lines as borders, much, much simpler is setting a background color for a
GridView
and proper padding & spacing:不幸的是,在查看源代码之后,除了采用向每个单元格添加边框的方法之外,我看不到任何简单的方法来添加边框。作为参考,我将在这里发布我的解决方案。
list_item.xml
list_selector.xml
item_border.xml
item_border_selected.xml
items_view.xml
由于所有线条在加入相邻单元格时尺寸都会加倍,因此我将分隔线尺寸设置为 1px 而不是 1dp,这样它在某些屏幕上不会显得太大。另外,我使网格视图具有负边距以隐藏两侧的线条。我希望这对某人有帮助。
Unfortunately, after looking at the source code, I could not see any easy way to add borders other than taking the approach of adding borders to the each cell. As a reference, I will post my solution here.
list_item.xml
list_selector.xml
item_border.xml
item_border_selected.xml
items_view.xml
Since all lines double in size as they join their neighboring cells, I made the divider size 1px instead of 1dp so it doesn't appear too large on some screens. Also, I made the grid view have negative margins to hide the lines on either side. I hope this helps someone.