onDraw中画弧这个地方不理解
老师,关于画弧那个方法,我查阅了api,了解到各个参数的含义,但在结合代码(代码中问号处)时看不懂
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
if (this.reset) {
canvas.drawColor(0xFFFFFFFF);
this.reset = false;
}
this.width = this.getMeasuredWidth();
this.height = this.getMeasuredHeight();
this.radius = this.getMeasuredWidth() / 2 - this.pathWidth;
//画笔颜色
this.pathPaint.setColor(this.PATHCOLOR);
//设置画笔宽度
this.pathPaint.setStrokeWidth((float) this.pathWidth);
//添加浮雕效果
this.pathPaint.setMaskFilter(this.emboss);
// 在中心的地方画个半径为r的圆
//#用粗为35的画笔画了一个半径为radius,圆心为(自身宽/2,自身高/2)的圆形(圆1)
canvas.drawCircle((float) (this.width / 2), (float) (this.height / 2), (float) this.radius, this.pathPaint);
this.pathPaint.setStrokeWidth(0.5F);
this.pathPaint.setColor(this.pathBorderColor);
//#用粗为0.5的画笔画了一个半径为radius+pathWidth/2+0.5,圆心为(自身宽/2,自身高/2)的圆形(圆2)
canvas.drawCircle((float) (this.width / 2), (float) (this.height / 2), (float) (this.radius + this.pathWidth / 2) + 0.5F, this.pathPaint);
//#圆3
canvas.drawCircle((float) (this.width / 2), (float) (this.height / 2), (float) (this.radius - this.pathWidth / 2) - 0.5F, this.pathPaint);
// SweepGradient sweepGradient = new SweepGradient((float)(this.width / 2), (float)(this.height / 2), this.arcColors, (float[])null);
this.fillArcPaint.setShader(sweepGradient);
this.fillArcPaint.setMaskFilter(this.mBlur);
this.fillArcPaint.setStrokeCap(Paint.Cap.ROUND);
this.fillArcPaint.setStrokeWidth((float) this.pathWidth);
this.oval.set((float) (this.width / 2 - this.radius),//left
(float) (this.height / 2 - this.radius), //top
(float) (this.width / 2 + this.radius), //right
(float) (this.height / 2 + this.radius));//bottom
//?
canvas.drawArc(this.oval, -90.0F, (float) this.progress / (float) this.max * 360.0F, false, this.fillArcPaint);
}
5
收起
正在回答
1回答
使用多个圆画出来的。让圆心偏移。计算好半径,让左侧对齐。你可以试想,用多个彩色球,左侧对齐那是就是不同颜色的弧度就出来了。祝:学习愉快
3.Android 高级应用与Kotlin综合实战
- 参与学习 人
- 提交作业 116 份
- 解答问题 1012 个
本阶段是提升项目经验的必备,除Android开发的高级控件,还有Android官方大力推荐的开发语言Kotlin,未来Android发展的方向,最后使用Kotlin来开发热门电商项目。
了解课程
恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧
0 星