自定义View画虚线的方法

@Override
protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);
    Paint paint = new Paint();
    paint.setStyle(Paint.Style.STROKE);
    paint.setColor(Color.DKGRAY);

    Path path = new Path();
    path.moveTo(0, 10);
    path.lineTo(200, 10);
    PathEffect effects = new DashPathEffect(new float[]{5,5,5,5},1);
    paint.setPathEffect(effects);
    canvas.drawPath(path, paint);
}

你可能感兴趣的:(自定义View画虚线的方法)