@@ -102,6 +102,11 @@ public class CircleProgressView extends View {
102
102
*/
103
103
private int mBlockAngle = 1 ;
104
104
105
+ /**
106
+ * 刻度偏移的角度大小
107
+ */
108
+ private float mTickOffsetAngle = 0 ;
109
+
105
110
/**
106
111
* 总刻度数
107
112
*/
@@ -243,6 +248,8 @@ private void init(Context context,AttributeSet attrs){
243
248
mTickSplitAngle = a .getInt (attr ,mTickSplitAngle );
244
249
}else if (attr == R .styleable .CircleProgressView_cpvBlockAngle ){
245
250
mBlockAngle = a .getInt (attr ,mBlockAngle );
251
+ }else if (attr == R .styleable .CircleProgressView_cpvTickOffsetAngle ){
252
+ mTickOffsetAngle = a .getInt (attr ,0 );
246
253
}else if (attr == R .styleable .CircleProgressView_cpvTurn ){
247
254
isTurn = a .getBoolean (attr ,isTurn );
248
255
}else if (attr == R .styleable .CircleProgressView_cpvCapRound ){
@@ -352,7 +359,7 @@ private void drawArc(Canvas canvas){
352
359
mPaint .setShader (null );
353
360
mPaint .setColor (mNormalColor );
354
361
//绘制外边框刻度
355
- canvas .drawArc (rectF , i * (mBlockAngle + mTickSplitAngle ) + mStartAngle , mBlockAngle , false , mPaint );
362
+ canvas .drawArc (rectF , i * (mBlockAngle + mTickSplitAngle ) + mStartAngle + mTickOffsetAngle , mBlockAngle , false , mPaint );
356
363
}
357
364
358
365
for (int i = currentBlockIndex ; i < currentBlockIndex + currentBlockIndex ; i ++) {
@@ -363,7 +370,7 @@ private void drawArc(Canvas canvas){
363
370
mPaint .setColor (mProgressColor );
364
371
}
365
372
//绘制外边框刻度
366
- canvas .drawArc (rectF , i * (mBlockAngle + mTickSplitAngle ) + mStartAngle , mBlockAngle , false , mPaint );
373
+ canvas .drawArc (rectF , i * (mBlockAngle + mTickSplitAngle ) + mStartAngle + mTickOffsetAngle , mBlockAngle , false , mPaint );
367
374
}
368
375
}else {
369
376
for (int i = 0 ; i < mTotalTickCount ; i ++) {
@@ -375,13 +382,13 @@ private void drawArc(Canvas canvas){
375
382
mPaint .setColor (mProgressColor );
376
383
}
377
384
//绘制外边框刻度
378
- canvas .drawArc (rectF , i * (mBlockAngle + mTickSplitAngle ) + mStartAngle , mBlockAngle , false , mPaint );
385
+ canvas .drawArc (rectF , i * (mBlockAngle + mTickSplitAngle ) + mStartAngle + mTickOffsetAngle , mBlockAngle , false , mPaint );
379
386
} else if (mNormalColor != 0 ){
380
387
//未选中的刻度
381
388
mPaint .setShader (null );
382
389
mPaint .setColor (mNormalColor );
383
390
//绘制外边框刻度
384
- canvas .drawArc (rectF , i * (mBlockAngle + mTickSplitAngle ) + mStartAngle , mBlockAngle , false , mPaint );
391
+ canvas .drawArc (rectF , i * (mBlockAngle + mTickSplitAngle ) + mStartAngle + mTickOffsetAngle , mBlockAngle , false , mPaint );
385
392
}
386
393
387
394
}
@@ -440,9 +447,9 @@ private void drawText(Canvas canvas){
440
447
mTextPaint .setTextAlign (Paint .Align .CENTER );
441
448
442
449
Paint .FontMetrics fontMetrics = mTextPaint .getFontMetrics ();
443
- // 计算文字高度
450
+ // 计算文字高度
444
451
float fontHeight = fontMetrics .bottom - fontMetrics .top ;
445
- // 计算文字baseline
452
+ // 计算文字baseline
446
453
float textBaseX = getWidth () / 2 + mLabelPaddingLeft - mLabelPaddingRight ;
447
454
float textBaseY = getHeight () - (getHeight () - fontHeight ) / 2 - fontMetrics .bottom + mLabelPaddingTop - mLabelPaddingBottom ;
448
455
if (isShowPercentText ){//是否显示百分比
@@ -660,6 +667,36 @@ public String getLabelText() {
660
667
return mLabelText ;
661
668
}
662
669
670
+ public boolean isShowLabel () {
671
+ return isShowLabel ;
672
+ }
673
+
674
+ public boolean isShowPercentText () {
675
+ return isShowPercentText ;
676
+ }
677
+
678
+ public boolean isShowTick () {
679
+ return isShowTick ;
680
+ }
681
+
682
+ public boolean isTurn () {
683
+ return isTurn ;
684
+ }
685
+
686
+ public boolean isCapRound () {
687
+ return isCapRound ;
688
+ }
689
+
690
+ public void setShowLabel (boolean showLabel ) {
691
+ isShowLabel = showLabel ;
692
+ invalidate ();
693
+ }
694
+
695
+ public void setShowPercentText (boolean showPercentText ) {
696
+ isShowPercentText = showPercentText ;
697
+ invalidate ();
698
+ }
699
+
663
700
public void setLabelPaddingLeft (float labelPaddingLeft ) {
664
701
this .mLabelPaddingLeft = labelPaddingLeft ;
665
702
invalidate ();
0 commit comments