4

I have a recycler view with 13 data items. I want to find out whether the first item of my list is visible or not?

I am aware about the methods like findFirstVisibleItemPosition and findLastVisibleItemPosition but they did not tell whether the first visible item is actually the first item of the list or not.

The problem that I am trying to solve is this, I have a view pager as the first item of my recycler view and I want to stop auto scroll when user scrolls down and it becomes completely invisible.

Please help if anyone has any idea about how to do this.

Ezio
  • 2,837
  • 2
  • 29
  • 45

1 Answers1

10

You can do it by checking if findFirstVisibleItemPosition is 0 or not, like this :

// layoutManager is your recycler view's layout manager
int position = layoutManager.findFirstVisibleItemPosition();
if(position != 0){
    stopAutoScroll();
}else{
    startAutoScroll();
}

i.e, if findFirstVisibleItemPosition returns 0 we should start auto scroll and if it is not 0, stop swiping.

Ashish Ranjan
  • 5,523
  • 2
  • 18
  • 39