Skip to content

Commit

Permalink
When calculating maxScrollY, take padding into account
Browse files Browse the repository at this point in the history
Also, refactored this logic into a helper.
  • Loading branch information
Adam Comella committed Nov 23, 2016
1 parent 85c7f5d commit 511188d
Showing 1 changed file with 9 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,12 @@ private boolean isScrollPerfLoggingEnabled() {
return mFpsListener != null && mScrollPerfTag != null && !mScrollPerfTag.isEmpty();
}

private int getMaxScrollY() {
int contentHeight = mContentView.getHeight();
int viewportHeight = getHeight() - getPaddingBottom() - getPaddingTop();
return Math.max(0, contentHeight - viewportHeight);
}

@Override
public void draw(Canvas canvas) {
if (mEndFillColor != Color.TRANSPARENT) {
Expand Down Expand Up @@ -332,10 +338,8 @@ protected void onOverScrolled(int scrollX, int scrollY, boolean clampedX, boolea
// more information.

if (!mScroller.isFinished() && mScroller.getCurrY() != mScroller.getFinalY()) {
int scrollRange = Math.max(
0,
getChildAt(0).getHeight() - (getHeight() - getPaddingBottom() - getPaddingTop()));
if (scrollY >= scrollRange) {
int scrollRange = getMaxScrollY();
if (scrollY >= getMaxScrollY()) {
mScroller.abortAnimation();
scrollY = scrollRange;
}
Expand Down Expand Up @@ -371,12 +375,8 @@ public void onLayoutChange(View v, int left, int top, int right, int bottom, int
return;
}

int contentHeight = mContentView.getMeasuredHeight();
int currentScrollY = getScrollY();
int thisHeight = getMeasuredHeight();

int maxScrollY = Math.max(0, contentHeight - thisHeight);

int maxScrollY = getMaxScrollY();
if (currentScrollY > maxScrollY) {
scrollTo(getScrollX(), maxScrollY);
}
Expand Down

0 comments on commit 511188d

Please sign in to comment.