使用 CursorAdapter 对 ListView 中的新行进行动画处理
有人对此有什么建议吗?目前,一个新行被添加到数据库中,我调用 requery()。我希望任何新行在第一次出现时都具有动画效果。许多行添加将发生在列表的中间,而不是顶部或底部。我希望这些能够以某种方式呈现动画,以便用户可以立即看到它们。
我正在考虑在我的适配器中可能有一个哈希图(或某些数据结构),它保存特定行的 id 和一个布尔值,说明它是否已被查看。在bindView中,检查该行id的布尔值,如果为真,则对某种闪烁进行动画处理,然后更新数据结构。这听起来合理吗?
另外,当重新查询光标时,我想将列表滚动到新行所在的位置。不幸的是,我认为在找到它之前,如果不暴力破解列表,我就无法知道它的位置。有什么建议吗?
Does anyone have any suggestions for doing this? At the moment, a new row gets added to the database and I call requery(). I'd like any new rows to animate when they show up for the first time. Many row additions will happen in the middle of the list, and not at the top or bottom. I'd like these to animate somehow so the user can see them immediately.
I was thinking of perhaps having a hashmap (or some data structure) in my Adapter that holds the id of a particular row and a boolean stating whether or not it has been viewed. In bindView, the boolean for the id of that row is checked and, if true, animates some flashing of some sort, and then updates the data structure. Does this sound plausible?
Also, when the Cursor is requeried, I'd like to scroll the list to where the new row is. Unfortunately, I don't think I can know its position without brute forcing through the list until I find it. Any suggestions?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
听起来您已经知道问题的答案了。是的,将项目 id 映射到“已查看”的 HashMap 听起来是解决此问题的一个好方法。如果某个项目是新的,则当该项目在 BindView 中呈现时,您可以将动画应用到项目视图。您还可以使用 ListView 类中的 smoothScrollToPosition 方法滚动到新的第一行。
要填充哈希图,您需要遍历所有项目,您也可以记录当时新的第一个项目。
It sounds like you already know the answer to your question. Yes a HashMap which maps item ids to "already viewed" sounds like a good solution to this problem. If an item is new you can apply an animation to the item view when that item is rendered in bindView. You can also use the smoothScrollToPosition method in the ListView class to scroll to the first row that is new.
To populate the hashmap you would need to walk through all the items, you can also record the first item that is new at that time also.