android recyclerview notifyItemInserted动画

android recyclerview notifyItemInserted animation

我不知道为什么会出现这种情况,但是调用 notifyItemInserted(0)(仅限第一位置)不会使视图动画化。在其他位置一切正常。

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

friendsList.remove(positionFriend);
friendsList.add(1, newFriend);
notifyItemInserted(1);
notifyItemRemoved(positionFriend+1);

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

friendsList.remove(positionFriend);
friendsList.add(0, newFriend);
notifyItemInserted(0);
notifyItemRemoved(positionFriend+1);

预期行为:在顶部插入元素并在此处插入动画。

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

动画开始了。但是你的旧位置零变为位置 1(在屏幕上可见),如果你向上滚动,新的位置零会出现。所以要让它可见,你必须在之后滚动回收器。

friendsList.remove(positionFriend);
friendsList.add(0, newFriend);
notifyItemInserted(0);
notifyItemRemoved(positionFriend+1);
recycler.scrollToPosition(0);