ksoichiro / Android-ObservableScrollView

Android library to observe scroll events on scrollable views.
http://ksoichiro.github.io/Android-ObservableScrollView/
Apache License 2.0
9.65k stars 2.06k forks source link

fix scrollY when the GridView has vertical spacing #249

Open jaredrummler opened 8 years ago

jaredrummler commented 8 years ago

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;
}
coveralls commented 8 years ago

Coverage Status

Coverage increased (+0.02%) to 93.384% when pulling 3abb0504676e9837f278312ede516e9fcaf992b8 on jaredrummler:master into 47a5fb2db5e93d923a8c6772cde48bbb7d932345 on ksoichiro:master.