Inserting RecyclerView items at zero position - always stay scrolled to top

前端 未结 5 644
不知归路
不知归路 2021-01-01 12:32

I have a pretty standard RecyclerView with a vertical LinearLayoutManager. I keep inserting new items at the top and I\'m calling notifyItemI

5条回答
  •  鱼传尺愫
    2021-01-01 12:51

    The only solution that worked for me was to reverse the recycler's layout by calling setReverseLayout() and setStackFromEnd() on its LinearLayoutManager.

    This might sound stupid, but the way RecyclerView handles adding items at the end of the list is what you need at the top. The only downsize of this is that you'd have to reverse your list and start adding items to the end instead.

提交回复
热议问题