Skip to content

Instantly share code, notes, and snippets.

@DHuckaby
Last active October 11, 2015 21:08
Show Gist options
  • Save DHuckaby/3919939 to your computer and use it in GitHub Desktop.
Save DHuckaby/3919939 to your computer and use it in GitHub Desktop.
Disable overscrolling on newer platforms, disable excess scrolling on certain Samsung devices
public class OverscrollUtilities {
public static void disableOverscrollMode(View view) {
if (view instanceof ListView) {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB && "samsung".equalsIgnoreCase(Build.MANUFACTURER)) {
try {
ListView listView = (ListView) view;
Method setEnableExcessScroll = ListView.class.getMethod("setEnableExcessScroll", Boolean.TYPE);
if (setEnableExcessScroll != null) {
setEnableExcessScroll.invoke(listView, Boolean.FALSE);
}
} catch (Exception ignore) {
// Silently ignore
}
}
}
try {
int OVER_SCROLL_NEVER = View.class.getField("OVER_SCROLL_NEVER").getInt(null);
Method setOverScrollMode = View.class.getMethod("setOverScrollMode", new Class[]{Integer.TYPE});
if (setOverScrollMode != null) {
setOverScrollMode.invoke(view, OVER_SCROLL_NEVER);
}
} catch (Exception ignore) {
// Silently ignore
}
}
}
@DHuckaby
Copy link
Author

It looks like some HTC devices contain the method setEnableExcessScroll and disabling it causes weird behavior at the end of the ListView, hence enabling it only on Samsung < 3.0 devices.

@doridori
Copy link

is the behaviour the one where it jumps back up the list when it reaches the end. I get this when setting the overscroll mode to OVER_SCROLL_NEVER

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment