Use Paint.setpathEffect(PathEffect effect) with DashPathEffect.
From docs: The intervals array must contain an even number of entries (>=2), with the even indices specifying the "on" intervals, and the odd indices specifying the "off" intervals.
paint.setPathEffect(new DashPathEffect(new float[]{on, off}, 0));
And add this to your DrawView constructor
public DrawView(Context context) {
super(context);
paint.setColor(Color.GREEN);
paint.setPathEffect(new DashPathEffect(new float[]{on, off}, 0));
}
EDIT complete code..
public class DrawView extends View {
Paint paint = new Paint();
public DrawView(Context context) {
super(context);
paint.setColor(Color.GREEN);
paint.setStyle(Style.STROKE);
}
@Override
public void onDraw(Canvas canvas) {
float width = canvas.getWidth();
float height = canvas.getHeight();
float size = height/(7*2); //just use 14 it's for convenience here
paint.setStrokeWidth(WIDTH);
paint.setPathEffect(new DashPathEffect(new float[]{size, size}, 0));
for(int i = 0 ; i < 7 ; i++) {
canvas.drawLine(0, size*i,
width, size*i, paint);
canvas.drawLine(size*i, 0,
height, size*i, paint);
}
}
}
you should be able to take this and simply alter it to fit you needs. You can also create rounded dots with this code.
paint.setStrokeJoin(Paint.Join.ROUND);
paint.setStrokeCap(Paint.Cap.ROUND);
paint.setDither(true);
paint.setAntiAlias(true);