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

Commit 1d886b6

Browse files
committed
Adding a gap parameter to the CirclePageIndicator
Allows for extra distance between the circles if desired
1 parent 8cd549f commit 1d886b6

File tree

5 files changed

+19
-2
lines changed

5 files changed

+19
-2
lines changed

library/res/values/vpi__attrs.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@
4747
<attr name="android:orientation"/>
4848
<!-- Radius of the circles. This is also the spacing between circles. -->
4949
<attr name="radius" format="dimension" />
50+
<!-- Additional spacing between the circles. -->
51+
<attr name="gap" format="dimension" />
5052
<!-- Whether or not the selected indicator snaps to the circles. -->
5153
<attr name="snap" format="boolean" />
5254
<!-- Color of the open circles. -->

library/res/values/vpi__defaults.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
<color name="default_circle_indicator_page_color">#00000000</color>
2121
<integer name="default_circle_indicator_orientation">0</integer>
2222
<dimen name="default_circle_indicator_radius">3dp</dimen>
23+
<dimen name="default_circle_indicator_gap">0dp</dimen>
2324
<bool name="default_circle_indicator_snap">false</bool>
2425
<color name="default_circle_indicator_stroke_color">#FFDDDDDD</color>
2526
<dimen name="default_circle_indicator_stroke_width">1dp</dimen>

library/src/com/viewpagerindicator/CirclePageIndicator.java

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ public class CirclePageIndicator extends View implements PageIndicator {
4545
private static final int INVALID_POINTER = -1;
4646

4747
private float mRadius;
48+
private float mGapWidth;
4849
private final Paint mPaintPageFill = new Paint(ANTI_ALIAS_FLAG);
4950
private final Paint mPaintStroke = new Paint(ANTI_ALIAS_FLAG);
5051
private final Paint mPaintFill = new Paint(ANTI_ALIAS_FLAG);
@@ -84,6 +85,7 @@ public CirclePageIndicator(Context context, AttributeSet attrs, int defStyle) {
8485
final int defaultStrokeColor = res.getColor(R.color.default_circle_indicator_stroke_color);
8586
final float defaultStrokeWidth = res.getDimension(R.dimen.default_circle_indicator_stroke_width);
8687
final float defaultRadius = res.getDimension(R.dimen.default_circle_indicator_radius);
88+
final float defaultGap = res.getDimension(R.dimen.default_circle_indicator_gap);
8789
final boolean defaultCentered = res.getBoolean(R.bool.default_circle_indicator_centered);
8890
final boolean defaultSnap = res.getBoolean(R.bool.default_circle_indicator_snap);
8991

@@ -100,6 +102,7 @@ public CirclePageIndicator(Context context, AttributeSet attrs, int defStyle) {
100102
mPaintFill.setStyle(Style.FILL);
101103
mPaintFill.setColor(a.getColor(R.styleable.CirclePageIndicator_fillColor, defaultFillColor));
102104
mRadius = a.getDimension(R.styleable.CirclePageIndicator_radius, defaultRadius);
105+
mGapWidth = a.getDimension(R.styleable.CirclePageIndicator_gap, defaultGap);
103106
mSnap = a.getBoolean(R.styleable.CirclePageIndicator_snap, defaultSnap);
104107

105108
Drawable background = a.getDrawable(R.styleable.CirclePageIndicator_android_background);
@@ -185,6 +188,15 @@ public float getRadius() {
185188
return mRadius;
186189
}
187190

191+
public void setGapWidth(float gap) {
192+
mGapWidth = gap;
193+
invalidate();
194+
}
195+
196+
public float getGapWidth() {
197+
return mGapWidth;
198+
}
199+
188200
public void setSnap(boolean snap) {
189201
mSnap = snap;
190202
invalidate();
@@ -227,9 +239,9 @@ protected void onDraw(Canvas canvas) {
227239
shortPaddingBefore = getPaddingLeft();
228240
}
229241

230-
final float threeRadius = mRadius * 3;
242+
final float threeRadius = mRadius * 3 + mGapWidth;
231243
final float shortOffset = shortPaddingBefore + mRadius;
232-
float longOffset = longPaddingBefore + mRadius;
244+
float longOffset = longPaddingBefore + mRadius + mGapWidth;
233245
if (mCentered) {
234246
longOffset += ((longSize - longPaddingBefore - longPaddingAfter) / 2.0f) - ((count * threeRadius) / 2.0f);
235247
}

sample/res/layout/themed_circles.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
android:layout_width="fill_parent"
3535
android:background="#FFCCCCCC"
3636
app:radius="10dp"
37+
app:gap="15dp"
3738
app:fillColor="#FF888888"
3839
app:pageColor="#88FF0000"
3940
app:strokeColor="#FF000000"

sample/src/com/viewpagerindicator/sample/SampleCirclesStyledMethods.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ protected void onCreate(Bundle savedInstanceState) {
2222
final float density = getResources().getDisplayMetrics().density;
2323
indicator.setBackgroundColor(0xFFCCCCCC);
2424
indicator.setRadius(10 * density);
25+
indicator.setGapWidth(15 * density);
2526
indicator.setPageColor(0x880000FF);
2627
indicator.setFillColor(0xFF888888);
2728
indicator.setStrokeColor(0xFF000000);

0 commit comments

Comments
 (0)