// 和系统普通进度条一样,0-100。 progressBar.setProgressType(CircleTextProgressbar.ProgressType.COUNT); // 改变进度条。 progressBar.setProgressLineWidth(30);// 进度条宽度。 // 设置倒计时时间毫秒,默认3000毫秒。 progressBar.setTimeMillis(3500); // 改变进度条颜色。 progressBar.setProgressColor(Color.RED); // 改变外部边框颜色。 progressBar.setOutLineColor(Color.RED); // 改变圆心颜色。 progressBar.setInCircleColor(Color.RED); // 如果需要自动倒计时,就会自动走进度。 progressBar.start(); // 如果想自己设置进度,比如100。 progressBar.setProgress(100);
@Override
public void layout(int left, int top, int right, int bottom) {
int w = right - left;
int h = bottom - top;
int size = w > h ? w : h;
if (w > h) {
bottom += (size - h);
} else {
right += (size - w);
}
super.layout(left, top, right, bottom);
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
int width = getMeasuredWidth();
int height = getMeasuredHeight();
int size = width > height ? width : height;
setMeasuredDimension(size, size);
}
Rect bounds = new Rect();
@Override
protected void onDraw(Canvas canvas) {
getDrawingRect(bounds);//获取view的边界
int size = bounds.height() > bounds.width() ? bounds.width() : bounds.height();
float outerRadius = size / 2; // 计算出绘制圆的半径
}
// 默认透明填充。
ColorStateList inCircleColors = ColorStateList.valueOf(Color.TRANSPARENT);
private void initialize(Context ctx, AttributeSet attributeSet) {
TypedArray typedArray = ctx.obtainStyledAttributes(attributeSet, R.styleable.Progressbar);
inCircleColors = typedArray.getColorStateList(R.styleable.Progressbar_circle_color);
typedArray.recycle();
}
int circleColor = inCircleColors.getColorForState(getDrawableState(), 0); mPaint.setStyle(Paint.Style.FILL); mPaint.setColor(circleColor); canvas.drawCircle(bounds.centerX(), bounds.centerY(), outerRadius - outLineWidth, mPaint);
mPaint.setStyle(Paint.Style.STROKE); mPaint.setStrokeWidth(outLineWidth); mPaint.setColor(outLineColor); canvas.drawCircle(bounds.centerX(), bounds.centerY(), outerRadius - outLineWidth / 2, mPaint);
//画字 Paint paint = getPaint(); paint.setColor(getCurrentTextColor()); paint.setAntiAlias(true); paint.setTextAlign(Paint.Align.CENTER); float textY = bounds.centerY() - (paint.descent() + paint.ascent()) / 2; canvas.drawText(getText().toString(), bounds.centerX(), textY, paint);
RectF mArcRect = new RectF();
Rect bounds = new Rect();
@Override
protected void onDraw(Canvas canvas) {
getDrawingRect(bounds);//获取view的边界
...
// 绘制进度条圆弧。
mPaint.setColor(progressLineColor);
mPaint.setStyle(Paint.Style.STROKE);
mPaint.setStrokeWidth(progressLineWidth);
mPaint.setStrokeCap(Paint.Cap.ROUND);
int deleteWidth = progressLineWidth + outLineWidth;
// 指定绘制区域
mArcRect.set(bounds.left + deleteWidth / 2, bounds.top + deleteWidth / 2,
bounds.right -deleteWidth / 2, bounds.bottom - deleteWidth / 2);
canvas.drawArc(mArcRect, 0, 360 * progress / 100, false, mPaint);
}
private int outLineColor = Color.BLACK;
private int outLineWidth = 2;
private ColorStateList inCircleColors = ColorStateList.valueOf(Color.TRANSPARENT);
private int circleColor;
private int progressLineColor = Color.BLUE;
private int progressLineWidth = 8;
private Paint mPaint = new Paint();
private RectF mArcRect = new RectF();
private int progress = 100;
final Rect bounds = new Rect();
@Override
protected void onDraw(Canvas canvas) {
//获取view的边界
getDrawingRect(bounds);
int size = bounds.height() > bounds.width() ? bounds.width() : bounds.height();
float outerRadius = size / 2;
//画内部背景
int circleColor = inCircleColors.getColorForState(getDrawableState(), 0);
mPaint.setStyle(Paint.Style.FILL);
mPaint.setColor(circleColor);
canvas.drawCircle(bounds.centerX(), bounds.centerY(), outerRadius - outLineWidth, mPaint);
//画边框圆
mPaint.setStyle(Paint.Style.STROKE);
mPaint.setStrokeWidth(outLineWidth);
mPaint.setColor(outLineColor);
canvas.drawCircle(bounds.centerX(), bounds.centerY(), outerRadius - outLineWidth / 2, mPaint);
//画字
Paint paint = getPaint();
paint.setColor(getCurrentTextColor());
paint.setAntiAlias(true);
paint.setTextAlign(Paint.Align.CENTER);
float textY = bounds.centerY() - (paint.descent() + paint.ascent()) / 2;
canvas.drawText(getText().toString(), bounds.centerX(), textY, paint);
//画进度条
mPaint.setColor(progressLineColor);
mPaint.setStyle(Paint.Style.STROKE);
mPaint.setStrokeWidth(progressLineWidth);
mPaint.setStrokeCap(Paint.Cap.ROUND);
int deleteWidth = progressLineWidth + outLineWidth;
mArcRect.set(bounds.left + deleteWidth / 2, bounds.top + deleteWidth / 2,
bounds.right - deleteWidth / 2, bounds.bottom - deleteWidth / 2);
canvas.drawArc(mArcRect, 0, 360 * progress / 100, false, mPaint);
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
int lineWidth = 4 * (outLineWidth + progressLineWidth);
int width = getMeasuredWidth();
int height = getMeasuredHeight();
int size = (width > height ? width : height) + lineWidth;
setMeasuredDimension(size, size);
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有