Skip to content

Commit

Permalink
fix scrollY when the GridView has vertical spacing
Browse files Browse the repository at this point in the history
  • Loading branch information
jaredrummler committed Jun 14, 2016
1 parent 47a5fb2 commit 3abb050
Showing 1 changed file with 10 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,14 @@ protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
}
}

@Override public int getVerticalSpacing() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
return super.getVerticalSpacing();
}
// getVerticalSpacing was added in 16. We could use reflection to get the value on pre-JB, but that would be expensive.
return 0;
}

private void init() {
mChildrenHeights = new SparseIntArray();
mHeaderViewInfos = new ArrayList<>();
Expand Down Expand Up @@ -435,7 +443,7 @@ private void onScrollChanged() {
}
}
}
mPrevScrolledChildrenHeight += mPrevFirstVisibleChildHeight + skippedChildrenHeight;
mPrevScrolledChildrenHeight += mPrevFirstVisibleChildHeight + skippedChildrenHeight + getVerticalSpacing();
mPrevFirstVisibleChildHeight = firstVisibleChild.getHeight();
} else if (firstVisiblePosition < mPrevFirstVisiblePosition) {
// scroll up
Expand All @@ -447,7 +455,7 @@ private void onScrollChanged() {
}
}
}
mPrevScrolledChildrenHeight -= firstVisibleChild.getHeight() + skippedChildrenHeight;
mPrevScrolledChildrenHeight -= firstVisibleChild.getHeight() + skippedChildrenHeight + getVerticalSpacing();
mPrevFirstVisibleChildHeight = firstVisibleChild.getHeight();
} else if (firstVisiblePosition == 0) {
mPrevFirstVisibleChildHeight = firstVisibleChild.getHeight();
Expand Down

0 comments on commit 3abb050

Please sign in to comment.