Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/kubernetes/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
android recyclerview notifyItemInserted动画_Android_Android Recyclerview - Fatal编程技术网

android recyclerview notifyItemInserted动画

android recyclerview notifyItemInserted动画,android,android-recyclerview,Android,Android Recyclerview,我不知道为什么会发生这种行为,但是调用notifyItemInserted(0)(仅限第一个位置)将不会设置视图的动画。在另一个位置,一切正常 在这种情况下工作的动画: friendsList.remove(positionFriend); friendsList.add(1, newFriend); notifyItemInserted(1); notifyItemRemoved(positionFriend+1); friendsList.remove(positionFriend); f

我不知道为什么会发生这种行为,但是调用
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);
在这种情况下,动画不起作用:

friendsList.remove(positionFriend);
friendsList.add(1, newFriend);
notifyItemInserted(1);
notifyItemRemoved(positionFriend+1);
friendsList.remove(positionFriend);
friendsList.add(0, newFriend);
notifyItemInserted(0);
notifyItemRemoved(positionFriend+1);
预期行为:在顶部插入元素并在那里插入动画


发生的情况:没有显示插入动画,实际上我认为“视觉上”,第一个元素消失,移动动画发生。

动画发生。但您的旧位置0变为位置1(在屏幕上可见),如果向上滚动,则会显示新的位置0。因此,要使其可见,您必须在之后滚动回收器

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

哦,这就是元素被移动的原因。这是一种奇怪的行为,你的修复应该是本地的。。。最后一件事,有没有办法不在适配器构造函数中传递引用就执行recycler.scrollToPosition(0)?我同意从用户的角度来看,这是一种奇怪的行为,但如果您想象一下RecyclerView在后面是如何编码的,这只是一种逻辑行为。我不知道,我通常从适配器外部调用
notify\uu
,让适配器只是数据列表和bindView代码。