Android recyclerview notifyItemInserted animation

I do not know why this is happening, but calling notifyItemInserted(0) (only the first position) will not animate the view. Everything works fine in other positions.

The animation working in this case:

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

Animation does not work in this case:

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

Expected Behavior: The element inserted at the top and the insertion animation happens there.

What happens: the insertion animation is not shown, in fact I think "visually", the first element disappears and the animation moves.

+5
source share
1 answer

animation takes place. But your old zero position becomes position 1 (visible on the screen), and when you scroll up, a new zero position appears. To make it visible, you will have to scroll through the recycler after that.

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

All Articles