How to save scroll position of RecyclerView in Android?

后端 未结 8 1390
耶瑟儿~
耶瑟儿~ 2020-11-27 06:20

I have Recycler view which lays inside of SwipeRefreshLayout. Also, have ability to open each item in another activity. After returning back to Recycler I need scroll to cho

8条回答
  •  Happy的楠姐
    2020-11-27 07:05

    User your recycler view linearlayoutmanager for getting scroll position

    int position = 0;
    if (linearLayoutManager != null) {
       scrollPosition = inearLayoutManager.findFirstVisibleItemPosition();
    }
    

    and when restoring use following code

    if (linearLayoutManager != null) {
      cardRecyclerView.scrollToPosition(mScrollPosition);
    }
    

    Hope this helps you

提交回复
热议问题