johnny_crq
johnny_crq

Reputation: 4391

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. 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.

Upvotes: 7

Views: 8135

Answers (1)

Budius
Budius

Reputation: 39836

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. 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);

Upvotes: 10

Related Questions