Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix scrollY when the GridView has vertical spacing #249

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

jaredrummler
Copy link

@jaredrummler jaredrummler commented Jun 14, 2016

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
Copy link

Coverage Status

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants