@@ -67,6 +67,7 @@ public class CircleFlowIndicator extends View implements FlowIndicator,
6767 private FadeTimer timer ;
6868 public AnimationListener animationListener = this ;
6969 private Animation animation ;
70+ private boolean mCentered = false ;
7071
7172 /**
7273 * Default constructor
@@ -117,6 +118,8 @@ public CircleFlowIndicator(Context context, AttributeSet attrs) {
117118 // Retrieve the fade out time
118119 fadeOutTime = a .getInt (R .styleable .CircleFlowIndicator_fadeOut , 0 );
119120
121+ mCentered = a .getBoolean (R .styleable .CircleFlowIndicator_centered , false );
122+
120123 initColors (activeColor , inactiveColor , activeType , inactiveType );
121124 }
122125
@@ -155,10 +158,17 @@ protected void onDraw(Canvas canvas) {
155158 if (viewFlow != null ) {
156159 count = viewFlow .getViewsCount ();
157160 }
161+
162+ float circleSeparation = 2 *radius +radius ;
163+ //this is the amount the first circle should be offset to make the entire thing centered
164+ float centeringOffset = 0 ;
165+
166+ int leftPadding = getPaddingLeft ();
167+
158168 // Draw stroked circles
159169 for (int iLoop = 0 ; iLoop < count ; iLoop ++) {
160- canvas .drawCircle (getPaddingLeft () + radius
161- + (iLoop * ( 2 * radius + radius )) ,
170+ canvas .drawCircle (leftPadding + radius
171+ + (iLoop * circleSeparation ) + centeringOffset ,
162172 getPaddingTop () + radius , radius , mPaintInactive );
163173 }
164174 float cx = 0 ;
@@ -167,7 +177,7 @@ protected void onDraw(Canvas canvas) {
167177 cx = (currentScroll * (2 * radius + radius )) / flowWidth ;
168178 }
169179 // The flow width has been upadated yet. Draw the default position
170- canvas .drawCircle (getPaddingLeft () + radius + cx , getPaddingTop ()
180+ canvas .drawCircle (leftPadding + radius + cx + centeringOffset , getPaddingTop ()
171181 + radius , radius , mPaintActive );
172182 }
173183
0 commit comments