如何动态改变listview的divider高度?
我有一个列表视图,其中应该有不同的分隔线高度 不同行之间。那么,我们如何设置分隔线的高度 动态地?
假设我有 10 行,分隔线高度应该为 5 前 2 行之间的分隔线高度应为 1 接下来的 5 行之间,依此类推。
有人可以让我知道这样做的方法吗?
I have a listview in which there should be different divider height
between different rows. So, how can we set the divider height
dynamically?
Suppose, I have 10 rows and there should be a divider height of 5
between first 2 rows and then there should be a divider height of 1
between next 5 rows and so on.
Can someone let me know the way of doing this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
一种方法是使分隔线成行。在
isEnabled
适配器方法中将它们设置为未启用。我对节标题这样做,但这几乎是同一件事。另一种方法是通过实现 onLayout 手动布局整个列表。如果分隔线可以是空白空间,则可以为行的根视图设置顶部或底部边距。在 xml 中,这将是:否则,只需将分隔线作为行的一部分即可。
One way would be to make the dividers rows. Set them as not enabled in your
isEnabled
adapter method. I do that for section headers, but it is almost the same thing. Another way would be to manually lay out your whole list by implementing onLayout. If the dividers can be empty space, it might work to set top or bottom margins for the root view of your rows. In xml that would be:Otherwise, just make the dividers part of the rows.