Home > Blockchain >  Know whether a view is completely visible in a recycler view from its adapter
Know whether a view is completely visible in a recycler view from its adapter

Time:05-13

I saw a lot of posts that show the currently entirely visible item in the recycler view but, from the activity. But, I want to know about that from the adapter. If the view is completely visible, I want to start playing a video and when it is hidden, I want to stop it.

CodePudding user response:

you have to set LayoutManager for RecyclerView. if you are using most common LinearLayoutManager, then it's have some methods for your prupose:

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

There are also similar methods in StaggeredGridLayoutManager

And general way would be to use bare LayoutManager and its isViewPartiallyVisible method

  • Related