如何使Android中列表视图中每个项目的分隔线部分?
我想动态更改分隔线高度。从我搜索到的内容来看,似乎可以通过将分隔线设置为 ListView 中每个项目的一部分来实现。但我对此不是很清楚。
那么,有人可以更具体地说明如何将 divider 作为 ListView
中项目的一部分吗?
I wanted to change the divider height dynamically. From whatever I have searched it seems that it is possible through setting divider as part of each item in ListView
. But I am not very clear with this.
So, can someone be more specific as how can one make the divider as part of item in ListView
?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
一种方法是在每行的底部添加分隔线。现在您必须在 getView 方法在列表适配器中,具体取决于您当前显示的项目。
A way to do this would be to include the divider at the bottom of each row. Now you have to set the height of the divider view in your getView method in your listadapter depending of the item you are showing at the moment.
没有什么比用图片来解释更好的了。这里我从网上找到了一张截图。我在上面做了一些标记。
这就是您想要实现的目标。
您可以将分隔板作为其中一项。
此外,您可以将分隔板作为项目的一部分。
这两种解决方案都没有使用
ListView
提供的真实分隔符。应将其高度设置为 0。听起来很傻,但确实有效。Nothing is better than explaining by picture. Here I found a screenshot from web. I made some mark on it.
This is what you want to achieve.
You can make the divider as one of the items.
Also, you can make the divider as a part of an item.
Neither of the 2 solutions uses real divider provided by
ListView
. It should be set 0 height. Sounds silly but it does effective.您可以将 android:footerDividersEnabled 设置为 false 并在适配器中添加分隔线。
You could set android:footerDividersEnabled to false and add dividers in your adapter.
在 ListActivity 调用中:
其中divider 是一个 Drawable 对象,您可以根据需要在代码中定义或编写该对象。
您还可以调用:
更改高度
In your ListActivity call:
where divider is a Drawable object which you can define or write in your code as you need to.
You can also call:
To change the height