Android-ObservableScrollView
Android-ObservableScrollView copied to clipboard
fix scrollY when the GridView has vertical spacing
The scrollY is off when items have vertical spacing. This fixes the scrollY jumping to incorrect values while scrolling.
This will still be an issue on pre-JB. If you did want to fix this problem for API 11-16, you could use reflection to get the vertical spacing. Example:
private Integer mVerticalSpacing;
@Override public int getVerticalSpacing() {
if (VERSION.SDK_INT >= VERSION_CODES.JELLY_BEAN) {
return super.getVerticalSpacing();
}
if (mVerticalSpacing == null) {
try {
Field field = GridView.class.getDeclaredField("mVerticalSpacing");
if (!field.isAccessible()) {
field.setAccessible(true);
}
mVerticalSpacing = field.getInt(this);
} catch (Exception e) {
mVerticalSpacing = 0;
}
}
return mVerticalSpacing;
}