Get visible items in RecyclerView

前端 未结 9 1966
礼貌的吻别
礼貌的吻别 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:04

    Finally, I found a solution to know if the current item is visible, from the onBindViewHolder event in the adapter.

    The key is the method isViewPartiallyVisible from LayoutManager.

    In your adapter, you can get the LayoutManager from the RecyclerView, which you get as parameter from the onAttachedToRecyclerView event.

提交回复
热议问题