16

I'd like to show/hide a view when the user over scroll the listview.

How can I detect the over-scroll? Is there any listener? I've tried OnScrollListener but it only notifies about onScrollStateChanged and onScroll

Jonik
  • 80,077
  • 70
  • 264
  • 372
Alexey
  • 7,127
  • 9
  • 57
  • 94

3 Answers3

19

You can override the method onOverScrolled, as it respond to the results of an over-scroll operation.

Sean
  • 5,176
  • 2
  • 34
  • 50
  • 3
    Indeed. you'll have to subclass it and add the new class instead of the regular ListView – Sean Oct 12 '13 at 13:10
  • I've been looking for this so long and it turns out to be so simple, thanks! – Leo Mar 10 '16 at 22:16
1

Just a little more complete answer :

@Override
protected void onOverScrolled(int scrollX, int scrollY, boolean clampedX, boolean clampedY) {
    super.onOverScrolled(scrollX, scrollY, clampedX, clampedY);

    View view = (View) getChildAt(getChildCount()-1);
    int diff = (view.getBottom()-(getHeight()+getScrollY()));

    if(diff==0) {
           //overscroll on bottom
       } else {
           //overscroll on top
       }    
}
ucMedia
  • 4,105
  • 4
  • 38
  • 46
1

scrollY = non-Zero and clampedY = true --> OverScroll state occure While Scrolling bottom to top

scrollY = Zero and clampedY = true --> OverScroll state occure While Scrolling top to bottom

so

@Override
protected void onOverScrolled(int scrollX, int scrollY, boolean clampedX, boolean clampedY) {
    super.onOverScrolled(scrollX, scrollY, clampedX, clampedY);

    if(clampedY){
        if(scrollY==0){
            //over Scroll at top
        }else {
            //over Scroll at Bottom
        }
    }
}
Vinayak Khedkar
  • 504
  • 5
  • 13