简体   繁体   中英

Detect the top of RecyclerView?

I have a RecyclerView, first its scrolled down, now when we scroll up, it reach top most point. I want to detect that .Is there any way? I have AppBar whose height is greater than device width. so it cause an fling on scroll. I thought by getting top reached listener manually expand AppBar to avoid fling.

    if (layoutManager.firstCompletelyVisibleItemPosition() == 0) {
    //this is the top of the RecyclerView 
    }

this code i already used but my issue is that i can't scroll up RecyclerView after putting this code. Because my RecyclerView uses GridLayoutManager with 3 columns.

If you have a LinearLayoutManager set on your RecyclerView you can use it to find the first visible item:

LinearLayoutManager layoutManager = new LinearLayoutManager(this);
recyclerview.setLayoutManager(layoutManager);

if (layoutManager.firstCompletelyVisibleItemPosition() == 0) {
    //this is the top of the RecyclerView
    //Do Something
}

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