Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android - disable overscroll on HorizontalScrollView

how I can disable overscroll on HorizontalScrollView under Android 2.2?

Edit

I use reflection for this:

    HorizontalScrollView hh = (HorizontalScrollView) findViewById(R.id.chartHorizontalView);
    viewCls = hh.getClass();
    try {
        Method m = viewCls.getMethod("setOverScrollMode",
                new Class[] { int.class });
        int OVER_SCROLL_NEVER = (Integer) viewCls.getField(
                "OVER_SCROLL_NEVER").get(hh);
        m.invoke(hh, OVER_SCROLL_NEVER);
    } catch (Exception e) {
        e.printStackTrace();
    }
like image 899
AYMADA Avatar asked May 21 '14 21:05

AYMADA


1 Answers

It's right in the docs, call setOverScrollMode

In stock AOSP there were no overscroll effects until Gingerbread, so the question of how to disable them makes no sense, sort of. Some manufacturers added their own overscroll effects, such as the TouchWiz bounce effect. Obviously, since the effects are not part of the SDK, there's no method in the SDK to disable them!

At the time of this writing, Froyo and below take up about 2%. In my opinion the sensible thing to do is to target sdk version >= 9 and use something like

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD) {
        horizontalScrollView.setOverScrollMode(View.OVER_SCROLL_NEVER);
    }

This way most users will not see the glow overscroll effect, but those 2% or less users running Froyo with TouchWiz will still see the bounce effect. If you really, absolutely must disable all overscroll effects you could use an onScrollListener to prevent scrolling past the beginning or end or use reflection to deal with TouchWiz specifically similar to this example or this one

like image 183
saik0 Avatar answered Nov 08 '22 09:11

saik0