Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

overScrollBy doesn't always bounce back in Lollipop (5.x) platform

I have overridden overScrollBy method in ScrollView based on the following post:

http://jasonfry.co.uk/blog/android-overscroll-revisited/

It is working fine on other platform version, but Lollipop is unable to bounce back if fling motion is applied to the ScrollView.

Anyone encountered this issue and found a workaround?

Called in constructorsetOverScrollMode(OVER_SCROLL_ALWAYS);

Here relevant code which I have overridden in my custom ScrollViewclass:

@Override
protected boolean overScrollBy(int deltaX, int deltaY, int scrollX,
                               int scrollY, int scrollRangeX, int scrollRangeY,
                               int maxOverScrollX, int maxOverScrollY, boolean isTouchEvent) {
    return super.overScrollBy(deltaX, deltaY, scrollX, scrollY,
            scrollRangeX, scrollRangeY, maxOverScrollX, OVER_SCROLL_AMOUNT,
            isTouchEvent);
}

Thanks.

like image 582
Niko Avatar asked May 06 '15 07:05

Niko


1 Answers

I digged into changes between KitKat an Lollipop ScrollView. Following code solves my issue.

@TargetApi(21)
@Override
public boolean dispatchNestedFling(float velocityX, float velocityY, boolean consumed) {
    // Not consumed means it wasn't handled because ScrollView
    // doesn't take over scrolling bounds into scroll range,
    // so we fling it ourselves to get it bounce back
    if (getOverScrollMode() == OVER_SCROLL_ALWAYS && !consumed) {
        fling((int) velocityY);

        return true;
    } else {
        return super.dispatchNestedFling(velocityX, velocityY, consumed);
    }
}
like image 173
Niko Avatar answered Nov 04 '22 21:11

Niko