diff --git a/scrollingpagerindicator/src/main/java/ru/tinkoff/scrollingpagerindicator/ScrollingPagerIndicator.java b/scrollingpagerindicator/src/main/java/ru/tinkoff/scrollingpagerindicator/ScrollingPagerIndicator.java index 0fa68b2..1765cc0 100644 --- a/scrollingpagerindicator/src/main/java/ru/tinkoff/scrollingpagerindicator/ScrollingPagerIndicator.java +++ b/scrollingpagerindicator/src/main/java/ru/tinkoff/scrollingpagerindicator/ScrollingPagerIndicator.java @@ -377,7 +377,8 @@ protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { @Override protected void onDraw(Canvas canvas) { - if (getDotCount() < visibleDotThreshold) { + int dotCount = getDotCount(); + if (dotCount < visibleDotThreshold) { return; } @@ -391,6 +392,12 @@ protected void onDraw(Canvas canvas) { + (int) (visibleFramePosition + visibleFrameWidth - getDotOffsetAt(firstVisibleDotPos)) / spaceBetweenDotCenters; + // If real dots count is less than we can draw inside visible frame, we move lastVisibleDotPos + // to the last item + if (firstVisibleDotPos == 0 && lastVisibleDotPos + 1 > dotCount) { + lastVisibleDotPos = dotCount - 1; + } + for (int i = firstVisibleDotPos; i <= lastVisibleDotPos; i++) { float dot = getDotOffsetAt(i); if (dot >= visibleFramePosition && dot < visibleFramePosition + visibleFrameWidth) { @@ -417,7 +424,7 @@ protected void onDraw(Canvas canvas) { // Additional scale for dots at corners if (itemCount > visibleDotCount) { float currentScaleDistance; - if (!looped && (i == 0 || i == getDotCount() - 1)) { + if (!looped && (i == 0 || i == dotCount - 1)) { currentScaleDistance = smallScaleDistance; } else { currentScaleDistance = scaleDistance;