How to get the Scrollposition in the Recyclerview/Layoutmanager?

后端 未结 7 1057
旧时难觅i
旧时难觅i 2020-12-23 20:12

How to get the scrollposition in Recyclerview or the Layoutmanager?

I can measure the scrollposition by adding an OnScrollListener

7条回答
  •  一整个雨季
    2020-12-23 21:08

    I came to the question just wanting to get the item position index that is currently scrolled to. For others who want to do the same, you can use the following:

    LinearLayoutManager myLayoutManager = myRecyclerView.getLayoutManager();
    int scrollPosition = myLayoutManager.findFirstVisibleItemPosition();
    

    You can also get these other positions:

    • findLastVisibleItemPosition()
    • findFirstCompletelyVisibleItemPosition()
    • findLastCompletelyVisibleItemPosition()

    Thanks to this answer for help with this. It also shows how to save and restore the scroll position.

提交回复
热议问题