how I can disable overscroll on HorizontalScrollView under Android 2.2?
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();
}
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With