Android中自定义圆环显示实时进度,仿里程进度
程序员文章站
2022-03-30 21:57:03
...
Android实现圆环进度条,显示出来实时进度
废话不多说,直接上效果图,普通的圆环进度条颜色是渐变,,这个是分段的颜色并且还要加刻度,下面看代码
白点是实时进度,自定义画上,并且保持实时进度
计算实时进度,白点所占位置
canvas.save();
paint_2.setStyle(Paint.Style.STROKE);
int sweep;
if (currentNum <= maxNum) {
double zhb = 0;
if (currentNum <= 40) {
zhb = 0;
} else if (currentNum <= 100 && currentNum > 40) {
double i = currentNum - 40;
String txdouble = txdouble(i, 60.0);
zhb = Double.parseDouble(txdouble)*0.5;
} else if (currentNum <= 160 && currentNum > 100) {
double i = currentNum - 100;
String txdouble = txdouble(i, 60.0);
String txdouble2 = txdouble(1, 3);
zhb = Double.parseDouble(txdouble) * Double.parseDouble(txdouble2) + 0.5;
} else if (currentNum <= 200 && currentNum > 160) {
double i = currentNum - 160;
String txdouble = txdouble(i, 40.0);
String txdouble2 = txdouble(1, 6);
String txdouble3 = txdouble(1, 3);
zhb = Double.parseDouble(txdouble) * Double.parseDouble(txdouble2) + Double.parseDouble(txdouble3) + 0.5;
}
sweep = (int)(zhb * 270);
} else {
sweep = sweepAngle;
}
画刻度
Paint paint = new Paint();
paint.setColor(getResources().getColor(R.color.color666));
paint.setAntiAlias(true);
paint.setTextSize(textSize);
canvas.drawText("40", CenterX - mEdge - mStrokeWidthBig - textSize * 2-dp2px(16),CenterY + mEdge + 20, paint);
canvas.drawText("60", CenterX - mRadius - mStrokeWidthBig - textSize* 2-dp2px(13), CenterY + 10, paint);
canvas.drawText("100", CenterX - textSize, CenterY - mRadius- mStrokeWidthBig - textSize-dp2px(10), paint);
canvas.drawText("160", CenterX + mRadius + mStrokeWidthBig + textSize+dp2px(7),CenterY + 10, paint);
canvas.drawText("200", CenterX + mEdge + mStrokeWidthBig + textSize+dp2px(9),CenterY + mEdge + 30, paint);
布局文件很简单
<com.jorli.test0.view.RoundIndicatorView
android:id="@+id/my_view"
android:layout_width="match_parent"
android:layout_height="match_parent" />
附上下载链接
https://download.csdn.net/download/wangbhan/12747022