Path pathRect1 = new Path();
RectF rectFRect1 = new RectF(50, 200 + paddingTop, 500, 400);
pathRect1.addRect(rectFRect1, Path.Direction.CCW);
mPaint.setStyle(Paint.Style.STROKE);
mPaint.setStrokeWidth(5);
canvas.drawPath(pathRect1, mPaint);
Path pathOval = new Path();
RectF rectFOval1 = new RectF(50, 600 + paddingTop, 500, 800);
pathOval.addOval(rectFOval1, Path.Direction.CW);
mPaint.setStyle(Paint.Style.STROKE);
mPaint.setStrokeWidth(5);
canvas.drawPath(pathOval, mPaint);
//统一圆角
Path pathRoundRect1 = new Path();
RectF rectFRoundRect = new RectF(50, 1000 + paddingTop, 500, 1200);
pathRoundRect1.addRoundRect(rectFRoundRect,50,50,Path.Direction.CW);
mPaint.setStyle(Paint.Style.STROKE);
mPaint.setStrokeWidth(5);
canvas.drawPath(pathRoundRect1, mPaint);
drawRightDescr(canvas, 1100 + paddingTop, "统一四角,addRoundRect");
//四角自定义
Path pathRoundRect2 = new Path();
RectF rectFRoundRect2 = new RectF(50, 1200 + paddingTop, 500, 1400);
float[] radii={0,0,50,50,0,0,50,50};
pathRoundRect2.addRoundRect(rectFRoundRect2,radii,Path.Direction.CW);
mPaint.setStyle(Paint.Style.STROKE);
mPaint.setStrokeWidth(5);
canvas.drawPath(pathRoundRect2, mPaint);
Path pathCircle = new Path();
pathCircle.addCircle(250,1700,100,Path.Direction.CW);
mPaint.setStyle(Paint.Style.STROKE);
mPaint.setStrokeWidth(5);
canvas.drawPath(pathCircle, mPaint);
Path pathArc = new Path();
RectF rectFArc = new RectF(50,2000+paddingTop,500,2200);
pathArc.addArc(rectFArc,0,120);
mPaint.setStyle(Paint.Style.STROKE);
mPaint.setStrokeWidth(5);
canvas.drawPath(pathArc, mPaint);
//不闭合
Path pathLines1 = new Path();
pathLines1.moveTo(250,2400+paddingTop);
pathLines1.lineTo(50,2600);
pathLines1.lineTo(450,2600);
mPaint.setStyle(Paint.Style.STROKE);
mPaint.setStrokeWidth(5);
canvas.drawPath(pathLines1,mPaint);
//闭合
Path pathLines2 = new Path();
pathLines2.moveTo(250,2600+paddingTop);
pathLines2.lineTo(50,2800);
pathLines2.lineTo(450,2800);
pathLines2.close();
mPaint.setStyle(Paint.Style.STROKE);
mPaint.setStrokeWidth(5);
canvas.drawPath(pathLines2,mPaint);
//五角星闭合
Path pathLines3 = new Path();
pathLines3.moveTo(250,2800+paddingTop);
pathLines3.lineTo(100,3000);
pathLines3.lineTo(400,2900);
pathLines3.lineTo(100,2900);
pathLines3.lineTo(100,2900);
pathLines3.lineTo(400,3000);
pathLines3.close();
mPaint.setStyle(Paint.Style.STROKE);
mPaint.setStrokeWidth(5);
canvas.drawPath(pathLines3,mPaint);
作者:Brainbg(白雨)
GitHub:https://github.com/Brainbg
博客:https://www.brainbg.com/
简书:https://www.jianshu.com/u/94518ede7100
CSDN:https://blog.csdn.net/u014720022