This Question and Answer are collected from stackoverflow and tested by JTuto community, is licensed under CC BY-SA 2.5. - CC BY-SA 3.0. - CC BY-SA 4.0.
I need to know which elements are currently displayed in my RecyclerView. There is no equivalent to the OnScrollListener.onScroll(…) method on ListViews. I tried to work with
View.getGlobalVisibleRect(...), but that hack is too ugly and does not always work too.
Someone any ideas?
First / last visible child depends on the
LayoutManager. If you are using
GridLayoutManager, you can use
int findFirstVisibleItemPosition(); int findFirstCompletelyVisibleItemPosition(); int findLastVisibleItemPosition(); int findLastCompletelyVisibleItemPosition();
GridLayoutManager layoutManager = ((GridLayoutManager)mRecyclerView.getLayoutManager()); int firstVisiblePosition = layoutManager.findFirstVisibleItemPosition();
LinearLayoutManager, first/last depends on the adapter ordering. Don’t query children from
LayoutManager may prefer to layout more items than visible for caching.
Answered By – yigit