Skip to content

Commit

Permalink
Respect top and bottom padding of RecyclerView when drawing thumb & t…
Browse files Browse the repository at this point in the history
…rack.

Resolves #6
  • Loading branch information
Tim Malseed committed Feb 8, 2019
1 parent e8546a5 commit 472ee5f
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -216,8 +216,8 @@ public Rect updateFastScrollerBounds(FastScrollRecyclerView recyclerView, int th
mBgBounds.right = recyclerView.getWidth() - (2 * recyclerView.getScrollBarWidth());
mBgBounds.left = mBgBounds.right - bgWidth;
}
mBgBounds.top = thumbOffsetY - bgHeight + recyclerView.getScrollBarThumbHeight() / 2;
mBgBounds.top = Math.max(edgePadding, Math.min(mBgBounds.top, recyclerView.getHeight() - edgePadding - bgHeight));
mBgBounds.top = recyclerView.getPaddingTop() - recyclerView.getPaddingBottom() + thumbOffsetY - bgHeight + recyclerView.getScrollBarThumbHeight() / 2;
mBgBounds.top = Math.max(recyclerView.getPaddingTop() + edgePadding, Math.min(mBgBounds.top, recyclerView.getPaddingTop() + recyclerView.getHeight() - edgePadding - bgHeight));
}
mBgBounds.bottom = mBgBounds.top + bgHeight;
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ protected int getAvailableScrollHeight(int adapterHeight, int yOffset) {
* AvailableScrollBarHeight = Total height of the visible view - thumb height
*/
protected int getAvailableScrollBarHeight() {
int visibleHeight = getHeight();
int visibleHeight = getHeight() - getPaddingTop() - getPaddingBottom();
return visibleHeight - mScrollbar.getThumbHeight();
}

Expand Down Expand Up @@ -234,7 +234,9 @@ protected void updateThumbPosition(ScrollPositionState scrollPosState, int rowCo

int scrollBarY = (int) (((float) scrollY / availableScrollHeight) * availableScrollBarHeight);
if (isLayoutManagerReversed()) {
scrollBarY = availableScrollBarHeight - scrollBarY;
scrollBarY = availableScrollBarHeight - scrollBarY + getPaddingBottom();
} else {
scrollBarY += getPaddingTop();
}

// Calculate the position and size of the scroll bar
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -258,10 +258,22 @@ public void draw(Canvas canvas) {
}

//Background
canvas.drawRect(mThumbPosition.x + mOffset.x, mOffset.y, mThumbPosition.x + mOffset.x + mWidth, mRecyclerView.getHeight() + mOffset.y, mTrack);
canvas.drawRect(
mThumbPosition.x + mOffset.x,
mOffset.y + mRecyclerView.getPaddingTop(),
mThumbPosition.x + mOffset.x + mWidth,
mRecyclerView.getHeight() + mOffset.y - mRecyclerView.getPaddingBottom(),
mTrack
);

//Handle
canvas.drawRect(mThumbPosition.x + mOffset.x, mThumbPosition.y + mOffset.y, mThumbPosition.x + mOffset.x + mWidth, mThumbPosition.y + mOffset.y + mThumbHeight, mThumb);
canvas.drawRect(
mThumbPosition.x + mOffset.x,
mThumbPosition.y + mOffset.y,
mThumbPosition.x + mOffset.x + mWidth,
mThumbPosition.y + mOffset.y + mThumbHeight,
mThumb
);

//Popup
mPopup.draw(canvas);
Expand Down

0 comments on commit 472ee5f

Please sign in to comment.