Skip to content
This repository was archived by the owner on Apr 19, 2018. It is now read-only.

fix CirclePageIndicator display incorrect #393

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 13 additions & 9 deletions library/src/com/viewpagerindicator/CirclePageIndicator.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ public class CirclePageIndicator extends View implements PageIndicator {
private int mOrientation;
private boolean mCentered;
private boolean mSnap;
private int mSpacing;

private int mTouchSlop;
private float mLastMotionX = -1;
Expand Down Expand Up @@ -227,11 +228,14 @@ protected void onDraw(Canvas canvas) {
shortPaddingBefore = getPaddingLeft();
}

final float threeRadius = mRadius * 3;
final float shortOffset = shortPaddingBefore + mRadius;
final float threeRadius = mRadius * 2 + mSpacing;
float shortOffset = shortPaddingBefore + mRadius;
float longOffset = longPaddingBefore + mRadius;
if (mCentered) {
longOffset += ((longSize - longPaddingBefore - longPaddingAfter) / 2.0f) - ((count * threeRadius) / 2.0f);
//the length of content view
float contentLongCount = count * (mRadius*2) + (count-1)*mSpacing;
longOffset += ((longSize - longPaddingBefore - longPaddingAfter) / 2.0f)
- (contentLongCount / 2.0f);
}

float dX;
Expand All @@ -254,12 +258,12 @@ protected void onDraw(Canvas canvas) {
}
// Only paint fill if not completely transparent
if (mPaintPageFill.getAlpha() > 0) {
canvas.drawCircle(dX, dY, pageFillRadius, mPaintPageFill);
canvas.drawCircle(dX, dY, mRadius-mPaintStroke.getStrokeWidth(), mPaintPageFill);
}

// Only paint stroke if a stroke width was non-zero
if (pageFillRadius != mRadius) {
canvas.drawCircle(dX, dY, mRadius, mPaintStroke);
canvas.drawCircle(dX, dY, pageFillRadius, mPaintStroke);
}
}

Expand All @@ -275,7 +279,7 @@ protected void onDraw(Canvas canvas) {
dX = shortOffset;
dY = longOffset + cx;
}
canvas.drawCircle(dX, dY, mRadius, mPaintFill);
canvas.drawCircle(dX, dY, mRadius-mPaintStroke.getStrokeWidth(), mPaintFill);
}

public boolean onTouchEvent(android.view.MotionEvent ev) {
Expand Down Expand Up @@ -468,8 +472,8 @@ private int measureLong(int measureSpec) {
} else {
//Calculate the width according the views count
final int count = mViewPager.getAdapter().getCount();
result = (int)(getPaddingLeft() + getPaddingRight()
+ (count * 2 * mRadius) + (count - 1) * mRadius + 1);
result = (int) (getPaddingLeft() + getPaddingRight()
+ (count * 2 * mRadius) + (count - 1) * mSpacing);
//Respect AT_MOST value if that was what is called for by measureSpec
if (specMode == MeasureSpec.AT_MOST) {
result = Math.min(result, specSize);
Expand All @@ -495,7 +499,7 @@ private int measureShort(int measureSpec) {
result = specSize;
} else {
//Measure the height
result = (int)(2 * mRadius + getPaddingTop() + getPaddingBottom() + 1);
result = (int) (2 * mRadius + getPaddingTop() + getPaddingBottom());
//Respect AT_MOST value if that was what is called for by measureSpec
if (specMode == MeasureSpec.AT_MOST) {
result = Math.min(result, specSize);
Expand Down