已更新的适配器内视图的 Android ListView 动画
我使用 ListView 来显示一些自定义数据,一旦数据在适配器中更新,我调用 notificationDatasetChanged(),因此视图将得到更新,所有这些都运行良好,但我的问题是我只想运行一次动画适配器更新时发生更改的项目。目前,我保留所有已更改对象的副本,并尝试通过 getView() 调用为正确的项目设置动画。
但是,如果我对每个 getView 调用只执行一次,那么大多数时候我在更改的项目上看不到动画。如果我在连续的 getView 调用中继续这样做,我会看到那些没有改变的项目上的动画,以及那些改变的项目一次又一次地获得动画。
我猜有时 android 调用 getView() 是出于其他原因,而不是立即显示生成的视图,这就是如果我这样做一次它就不起作用的原因。
这样做的正确方法是什么?
谢谢, 图腾。
Im using ListView to to show some custom data, once data is updated in the adapter i call notifyDatasetChanged(), so the view will get updated, all of this works well, my issue though is i would like to run an animation once only on items that got changed when the adapter was updated. currently i keep a copy of all the changed objects and i tried to animate the correct items through the getView() call.
However if i do it only once for every getView call then i see no animation most of the time on items that changed. if i continue to do so in successive getView calls i see animation on items that don not change as well and also the ones that changed get animated again and again.
Im guessing sometimes android calls the getView() for other reasons than showing the generated view immediately, and thats the reason it doesnt work if i do it once.
What is the correct way to do this?
Thanks,
Totem.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果有人也遇到这个问题,解决方法是扩展 listview 并覆盖
并在内部手动设置大小,并
确保不要调用超级 onMeasure() 因为它会使用一次性视图在所有子视图上调用 getview来测量它们。
If anyone is has this problem as well the way around it is to extend listview and override
and inside manually set the size with
make sure not to call the super onMeasure() since it will call getview on all your children views with a disposeable view just to measure them.