CornerPathEffect 可以用来画圆角,比如我们想要画一个圆角矩形,那么就可以使用。
代码:
public class CornerPathEffectViewTest extends View {private Paint paint;private Path path;private PathEffect pathEffect;private int startY;private Path pathAll;public CornerPathEffectViewTest(Context context) {super(context);init(context);}public CornerPathEffectViewTest(Context context, @Nullable AttributeSet attrs) {super(context, attrs);init(context);}public CornerPathEffectViewTest(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {super(context, attrs, defStyleAttr);init(context);}private void init(Context context) {paint = new Paint();paint.setColor(Color.RED);paint.setAntiAlias(true);paint.setStyle(Paint.Style.STROKE);paint.setStrokeWidth(5);paint.setTextSize(40);path = new Path();path.addRect(new RectF(20,20,400,400), Path.Direction.CW);startY = 120;pathEffect = new CornerPathEffect(20);paint.setPathEffect(pathEffect);}@Overrideprotected void onDraw(Canvas canvas) {super.onDraw(canvas);canvas.drawPath(path,paint);}}