RecyclerView notifyDataSetChanged scrolls to top position

前端 未结 8 2010
北海茫月
北海茫月 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:13

    notifyItemChanged() make the RecyclerView scroll and jump to UP

    android:descendantFocusability="blocksDescendants"
    

    Horizontal recyclerView inside vertical recyclerView generally causes that problem and this is best approach to get rid of problem. Don't put this attr into horizontal recyclerViews, it needs to be in only Parent (vertical RecyclerView).

    0 讨论(0)
  • 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);
    
    0 讨论(0)
提交回复
热议问题