RecyclerView notifyDataSetChanged scrolls to top position

前端 未结 8 2059
北海茫月
北海茫月 2020-12-11 00:11

when calling notifyDataSetChanged on RecyclerView it doesn\'t retain the scroll position and scrolls to top, is there any solution to retain it\'s

8条回答
  •  伪装坚强ぢ
    2020-12-11 01:14

    RecycleViews will scroll back to the top on any variant of notifyDataSetChanged if they don't have a layout manager. Here's an example of how to set one.

    LinearLayoutManager linearLayoutManager = new LinearLayoutManager(context, OrientationHelper.VERTICAL, false);
    recycleView.setLayoutManager(linearLayoutManager);
    

提交回复
热议问题