简体   繁体   中英

Find if the first visible item in the recycler view is the first item of the list or not

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.

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();
}

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM