一、setStyle()
mPaint.setShadowLayer(20, 5, 5, Color.RED);
mPaint.setStyle(Paint.Style.FILL);
canvas.drawCircle(50, 100, 50, mPaint);
mPaint.setStyle(Paint.Style.FILL_AND_STROKE);
canvas.drawCircle(200, 100, 50, mPaint);
mPaint.setStyle(Paint.Style.STROKE);
canvas.drawCircle(350, 100, 50, mPaint);
mPaint.setTextSize(30);
mPaint.setStrokeWidth(2);
mPaint.setStyle(Paint.Style.FILL);
canvas.drawText("hello world!", 300,300, mPaint);
1·三种主题:FILL 、 FILL_AND_STROKE 、 STROKE 对应填充内部、描边并填充内部、仅描边
mPaint.setShadowLayer(20, 5, 5, Color.RED);为画笔设置阴影效果,20 blur模糊的半径, 5,5阴影的x,y轴的偏移量,Color.RED阴影的颜色
效果:
![]()
![]()
二、setStrokeCap(Cap cap)(端)
The Cap specifies the treatment for the beginning and ending of stroked lines and paths. The default is BUTT.
用于指定描边线和路径开始和结束的处理方式, 默认是BUTT,三种分别是BUTT、ROUND、SQUARE
效果:
![]()
三、setStrokeJoin(Join join)(拐角)
The Join specifies the treatment where lines and curve segments join on a stroked path. The default is MITER.
用于指定直线和弧线部分在描边路径上连接的处理方式,默认是MITER,
三种分别是:BEVEL(斜边)、MITER、ROUND(圆形)
效果:
![]()
四、setTextAlign(Align align)
Align specifies how drawText aligns its text relative to the [x,y] coordinates. The default is LEFT.
用于指定文字的对齐方式
效果:
canvas.drawCircle(100, 100, 50, mPaint);
mPaint.setDither(true);
canvas.drawCircle(200, 100, 50, mPaint);
mPaint.setTextAlign(Paint.Align.CENTER);
canvas.drawText("1234567890", 100, 200, mPaint);
mPaint.setSubpixelText(true);
mPaint.setUnderlineText(true);
mPaint.setStrikeThruText(true);
mPaint.setFakeBoldText(true);
canvas.drawText("1234567890", 200, 200, mPaint);