Reputation: 419
The code:
int width = canvas.getWidth();
int height = canvas.getHeight();
int shift = 0;
RectF rect = new RectF(0 + shift, 0 + shift, width - 1 - shift, height - 1 - shift);
Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
paint.setStyle(Paint.Style.STROKE);
paint.setStrokeWidth(30);
paint.setColor(0xff009900);
float angle_step = 180 / 5;
for (int i=0; i<5; i++) {
canvas.drawArc(rect, 180 + angle_step * i, angle_step, true, paint);
}
The result:
The question: How to make inner stroke instead of outer?
Thanks
Upvotes: 2
Views: 728
Reputation: 2539
As @Mike M (all credits goes to him) mentioned the solution would be as following:
UPDATE: instead of using Paint.Joint.Round you could use mitter limit as following:
int width = canvas.getWidth();
int height = canvas.getHeight();
int shift = 0;
RectF rect = new RectF(0 + shift, 0 + shift, width - 1 - shift, height - 1 - shift);
Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
paint.setStyle(Paint.Style.STROKE);
//Make stroke mitter to affect only very sharp angles
paint.setStrokeMiter(1.8f);
int strokeWidth = 30;
paint.setStrokeWidth(strokeWidth);
paint.setColor(0xff009900);
//inset drawing rect by the half of stroke width
rect.inset(strokeWidth/2,strokeWidth/2);
float angle_step = 180 / 5;
for (int i=0; i<5; i++) {
canvas.drawArc(rect, 180 + angle_step * i, angle_step, true, paint);
}
This will give you sharp adges on left and right.
The result:
Upvotes: 4