CircleProgressBar

今天又写了一个demo,带有两个进度值的 圆环进度条,原谅我是个小白,只能写一写简单的自定义控件,我会继续努力的。。先看效果图

001.gif

<pre>
@Override
protected void onDraw(Canvas canvas) {
/*偏移量*/
float dMax = (dotDiameter - maxProgressWidth)*0.5F;
float dFirst = (dotDiameter - firstProgressWidth)*0.5F;
float dSecond = (dotDiameter - secondProgressWidth)*0.5F;
/*1.圆心(x,y)坐标值*/
float centerX = (width - getPaddingLeft() - getPaddingRight()) / 2.0f;
float centerY = (height - getPaddingTop() - getPaddingBottom()) / 2.0f;
/*2.圆环半径*/
float maxRadius = centerY - maxProgressWidth / 2;
float firstRadius = centerY - firstProgressWidth / 2;
float secondRadius = centerY - secondProgressWidth / 2;
if (getWidth() >= getHeight()) {
maxRadius = centerY - maxProgressWidth / 2;
firstRadius = centerY - firstProgressWidth / 2;
secondRadius = centerY - secondProgressWidth / 2;
} else {
maxRadius = centerX - maxProgressWidth / 2;
firstRadius = centerX - firstProgressWidth / 2;
secondRadius = centerX - secondProgressWidth / 2;
}

maxRectF.left =  centerX - maxRadius + dMax;
maxRectF.right = centerX + maxRadius - dMax;
maxRectF.top = centerY - maxRadius + dMax;
maxRectF.bottom = centerY + maxRadius - dMax;

firstRectF.left =  centerX - firstRadius + dFirst;
firstRectF.right = centerX + firstRadius - dFirst;
firstRectF.top = centerY - firstRadius + dFirst;
firstRectF.bottom = centerY + firstRadius - dFirst;

secondRectF.left = centerX - secondRadius + dSecond;
secondRectF.right = centerX + secondRadius - dSecond;
secondRectF.top = centerY - secondRadius + dSecond;
secondRectF.bottom = centerY + secondRadius - dSecond;

canvas.drawArc(maxRectF, 0, 360 , false, maxProgressPaint);

float firstAngle = (float) 360 \* firstProgress / (float) maxProgress;
float secondAngle = ((float) 360 \* secondProgress / (float) maxProgress);
float dotAngle =  (float) (Math.PI\*secondAngle/180.0F);

canvas.drawArc(firstRectF, 0 - 90, firstAngle, false, firstProgressPaint);
canvas.drawArc(secondRectF, 0 - 90, secondAngle , false, secondProgressPaint);

float dotCx = (float) (width\*0.5 + (width - dotDiameter)\*0.5 \* Math.sin(dotAngle));
float dotCy = (float) (height\*0.5 - (height -dotDiameter) \*0.5 \* Math.cos(dotAngle));
if(canDisplayDot){
    canvas.drawCircle(dotCx, dotCy, dotDiameter \* 0.5F, dotPaint);
}

}
</pre>

源码地址

<a href="https://github.com/Alex-Cin/CircleProgressBar">https://github.com/Alex-Cin/CircleProgressBar</a>

apk 下载地址

<a href="http://fir.im/z3xb">http://fir.im/z3xb</a>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值