Get visible items in RecyclerView

前端 未结 9 2097
礼貌的吻别
礼貌的吻别 2020-11-22 07:17

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 w

9条回答
  •  迷失自我
    2020-11-22 08:18

    Following Linear / Grid LayoutManager methods can be used to check which items are visible

    int findFirstVisibleItemPosition();
    int findLastVisibleItemPosition();
    int findFirstCompletelyVisibleItemPosition();
    int findLastCompletelyVisibleItemPosition();
    

    and if you want to track is item visible on screen for some threshold then you can refer to the following blog.

    https://proandroiddev.com/detecting-list-items-perceived-by-user-8f164dfb1d05

提交回复
热议问题