How to detect overscroll in Android ListView?

橙三吉。 提交于 2019-12-01 02:35:50

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

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
       }    
}

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
        }
    }
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!