本文主要是介绍自定义view - 画弧线填充描边与使用中心,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
设置画笔样式的时候是这样的:
mPaint.setStyle(Paint.Style.FILL);
//设置画笔模式为填充
实际上画笔有三种模式,如下:
STROKE //描边
FILL //填充
FILL_AND_STROKE //描边加填充
Paint paint = new Paint();
paint.setColor(Color.BLUE);
paint.setStrokeWidth(40); //为了实验效果明显,特地设置描边宽度非常大// 描边
paint.setStyle(Paint.Style.STROKE);
canvas.drawCircle(200,200,100,paint);// 填充
paint.setStyle(Paint.Style.FILL);
canvas.drawCircle(200,500,100,paint);// 描边加填充
paint.setStyle(Paint.Style.FILL_AND_STROKE);
canvas.drawCircle(200, 800, 100, paint);
由图可以看出,填充是内容,描边是边界。描边的宽度向外扩展。
画弧线的对比
注意:顺时针方向为角度正方向
paint.setStyle(Paint.Style.STROKE);//描边RectF rectF1 = new RectF(100f, 100f, 500f, 300f);canvas.drawArc(rectF1, 270, 90, false, paint);//不用中心paint.setStyle(Paint.Style.STROKE);//描边RectF rectF2 = new RectF(100f, 300f, 500f, 500f);canvas.drawArc(rectF2, 270, 90, true, paint);//用中心paint.setStyle(Paint.Style.FILL);//填充RectF rectF3 = new RectF(100f, 500f, 500f, 700f);canvas.drawArc(rectF3, 270, 90, false, paint);//不用中心paint.setStyle(Paint.Style.FILL);//填充RectF rectF4 = new RectF(100f, 700f, 500f, 900f);canvas.drawArc(rectF4, 270, 90, true, paint);//用中心paint.setStyle(Paint.Style.FILL_AND_STROKE);//描边加填充RectF rectF5 = new RectF(100f, 900f, 500f, 1100f);canvas.drawArc(rectF5, 270, 90, false, paint);//不用中心paint.setStyle(Paint.Style.FILL_AND_STROKE);//描边加填充RectF rectF6 = new RectF(100f, 1100f, 500f, 1300f);canvas.drawArc(rectF6, 270, 90, true, paint);//用中心
效果图:
实心文字:
textPaint.setStyle(Paint.Style.FILL);
空心文字:
textPaint.setStyle(Paint.Style.STROKE);
描边,不用中心
mPaint.setStyle(Paint.Style.STROKE);//描边
canvas.drawArc(rectF3,270,90,false,mPaint);//用中心
描边,用中心
mPaint.setStyle(Paint.Style.STROKE);//描边
canvas.drawArc(rectF3,270,90,true,mPaint);//用中心
填充,不用中心
mPaint.setStyle(Paint.Style.FILL);//填充
canvas.drawArc(rectF3,270,90,false,mPaint);//用中心
填充,用中心
mPaint.setStyle(Paint.Style.FILL);//填充
canvas.drawArc(rectF3,270,90,true,mPaint);//用中心
填充描边,不用中心
mPaint.setStyle(Paint.Style.FILL_AND_STROKE);//描边填充canvas.drawArc(rectF3,270,90,false,mPaint);//不用中心
填充描边,用中心
mPaint.setStyle(Paint.Style.FILL_AND_STROKE);//描边填充
canvas.drawArc(rectF3,270,90,true,mPaint);//不用中心
这篇关于自定义view - 画弧线填充描边与使用中心的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!