[英]android recyclerview notifyItemInserted animation
I don't know why this behaviour is happening, but calling notifyItemInserted(0)
(first position only) won't animate the view. 我不知道为什么会发生这种情况,但调用
notifyItemInserted(0)
(仅限第一个位置)将不会为视图设置动画。 Everything works fine in another positions. 在其他位置一切正常。
Animation working in this case: 在这种情况下工作的动画:
friendsList.remove(positionFriend);
friendsList.add(1, newFriend);
notifyItemInserted(1);
notifyItemRemoved(positionFriend+1);
Animation not working in this case: 动画在这种情况下不起作用:
friendsList.remove(positionFriend);
friendsList.add(0, newFriend);
notifyItemInserted(0);
notifyItemRemoved(positionFriend+1);
Expected behaviour: Element inserted at the top and insert animation happens there. 预期行为:元素插入顶部并插入动画。
What is happening: No insert animation is shown, actually i think 'visually', first element disappears and move animation happens. 发生了什么:没有显示插入动画,实际上我认为'视觉',第一个元素消失,移动动画发生。
the animation happens. 动画发生了。 But your old position zero becomes position 1 (visible on the screen) and the new position zero appears if you scroll up.
但是您的旧位置零变为位置1(在屏幕上可见),如果向上滚动,则会出现新位置零。 So to make it visible you have to scroll the recycler afterwards.
因此,为了使其可见,您必须在之后滚动回收器。
friendsList.remove(positionFriend);
friendsList.add(0, newFriend);
notifyItemInserted(0);
notifyItemRemoved(positionFriend+1);
recycler.scrollToPosition(0);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.