Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android - stroke inside path

Tags:

android

I want to draw a shape as defined using Path with a stroke width of 5 where all of the stroke is inside the Path rather than half the stroke inside and half outside.

Thanks,

Carl

like image 736
user2430147 Avatar asked May 28 '13 21:05

user2430147


People also ask

What is stroke in Android XML?

Sometimes you want an outline around your shape and to do that you can use the stroke tag. You can specify the width and color of the outline using android:width and android:color.

What is stroke width android?

The stroke-width attribute is a presentation attribute defining the width of the stroke to be applied to the shape.


1 Answers

It seems it can not control the position of the stroke (i.e, inside, center or outside). For more info refer to: Android Paint stroke width positioning

My solution is offset the stroke width while drawing e.g.,

final RectF rectF = new RectF(halfStrokeWidth, halfStrokeWidth, width - halfStrokeWidth, height - halfStrokeWidth);
canvas.drawRoundRect(rectF, roundX, roundY, paint);
like image 127
chrisli Avatar answered Sep 21 '22 15:09

chrisli