android recyclerview notifyItemInserted动画

joh*_*crq 5 android android-recyclerview

我不知道为什么会发生这种情况,但调用notifyItemInserted(0)(仅限第一个位置)不会为视图设置动画.在其他位置一切正常.

在这种情况下工作的动画:

friendsList.remove(positionFriend);
friendsList.add(1, newFriend);
notifyItemInserted(1);
notifyItemRemoved(positionFriend+1);
Run Code Online (Sandbox Code Playgroud)

动画在这种情况下不起作用:

friendsList.remove(positionFriend);
friendsList.add(0, newFriend);
notifyItemInserted(0);
notifyItemRemoved(positionFriend+1);
Run Code Online (Sandbox Code Playgroud)

预期行为:元素插入顶部并插入动画.

发生了什么:没有显示插入动画,实际上我认为'视觉',第一个元素消失,移动动画发生.

Bud*_*ius 10

动画发生了.但是您的旧位置零变为位置1(在屏幕上可见),如果向上滚动,则会出现新位置零.因此,为了使其可见,您必须在之后滚动回收器.

friendsList.remove(positionFriend);
friendsList.add(0, newFriend);
notifyItemInserted(0);
notifyItemRemoved(positionFriend+1);
recycler.scrollToPosition(0);
Run Code Online (Sandbox Code Playgroud)