5

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.

Bincy Baby
  • 3,941
  • 5
  • 36
  • 62
  • Possible duplicate of [How to know whether a RecyclerView / LinearLayoutManager is scrolled to top or bottom?](http://stackoverflow.com/questions/27841740/how-to-know-whether-a-recyclerview-linearlayoutmanager-is-scrolled-to-top-or-b) – N J Jan 11 '17 at 06:15
  • i have edited my question – Bincy Baby Jan 11 '17 at 06:20

1 Answers1

10

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
}
Rajat Mittal
  • 413
  • 5
  • 19
gsb
  • 5,520
  • 8
  • 49
  • 76
  • 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. – Bincy Baby Jan 11 '17 at 06:20
  • 6
    The correct method name is `findFirstCompletelyVisibleItemPosition` i guess – Cerlin Jun 23 '17 at 04:33
  • 2
    'findFirstCompletelyVisibleItemPosition' won't work if your items are larger than your screen (can happen easily on small devices) – Katharina Sep 13 '17 at 07:34