RecyclerView notifyItemInserted() Animation not showing when position is 0 but works fine with other position

孤者浪人 提交于 2021-02-19 02:19:06

问题


I am using

data.add(0,item);
notifyItemInserted(0);

This works fine as long as the items space is not filled up. After that, animation is not seen.

animation works fine when i do

data.add(1,item);
notifyItemInserted(1);

How to add items in 0 position and show animation all the time. Do I have to use scrollToPosition?


回答1:


call scrollToPosition(0) if you wan't it to scroll to position 0 after new item is added. RecyclerView will just keep the current top item in place, which is why you are not seeing the new item. (the new item is being added above the visible area).



来源:https://stackoverflow.com/questions/31787531/recyclerview-notifyiteminserted-animation-not-showing-when-position-is-0-but-w

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!