Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 644
johnny_crq Avatar asked May 22 '15 11:05

johnny_crq


1 Answers

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);
like image 163
Budius Avatar answered Nov 04 '22 16:11

Budius