Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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

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.

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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

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

There are also similar methods in StaggeredGridLayoutManager, e.g. findFirstVisibleItemPositions

And general way would be to use bare LayoutManager and its isViewPartiallyVisible method, but this probably needs more your code for particular use case

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading