RecyclerView notifyItemInserted()位置为0时不显示动画,但与其他位置配合正常 [英] RecyclerView notifyItemInserted() Animation not showing when position is 0 but works fine with other position

查看:138
本文介绍了RecyclerView notifyItemInserted()位置为0时不显示动画,但与其他位置配合正常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用

data.add(0,item);
notifyItemInserted(0);

只要未填满项目空间,此方法就可以正常工作.之后,看不到动画.

This works fine as long as the items space is not filled up. After that, animation is not seen.

我做动画时效果很好

data.add(1,item);
notifyItemInserted(1);

如何在0位置添加项目并始终显示动画.我必须使用scrollToPosition吗?

How to add items in 0 position and show animation all the time. Do I have to use scrollToPosition?

推荐答案

如果添加新项目后不希望滚动到位置0,请调用 scrollToPosition(0).RecyclerView只会将当前的主要项目保留在原位,这就是为什么您看不到新项目的原因.(新项目将添加到可见区域的上方).

call scrollToPosition(0) if you wan't it to scroll to position 0 after new item is added. RecyclerView will just keep the current top item in place, which is why you are not seeing the new item. (the new item is being added above the visible area).

这篇关于RecyclerView notifyItemInserted()位置为0时不显示动画,但与其他位置配合正常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆