You can use the CornerPathEffect class for reference! We give an example of a rounded shape.
When drawing a background with a radius using the canvas.drawRoundRect () method and Style.FILL color sets, you can get a round rectangle shape. And then, by drawing a round rectangular frame on it with Style.STROKE and the width of the paint settings, using the same method, you can get the border.
The code:
mBackgroundRectF.set(0, 0, mWidth, mHeight); canvas.drawRoundRect(mBackgroundRectF, mRadius, mRadius, mBackgroundPaint);
Now it seems this is not the one I need, which has an offset between the background and the border:
before
Try CornerPathEffect:
mBackgroundRectF.set(0, 0, mWidth, mHeight); canvas.drawRoundRect(mBackgroundRectF, mRadius, mRadius, mBackgroundPaint); // edge ajustment because paint stroke style is center align float edge = mBorderWidth / 2; mBackgroundRectF.set(edge, edge, mWidth - edge, mHeight - edge); // use CornerPathEffect and then use drawRect() method mBorderPaint.setPathEffect(new CornerPathEffect(mRadius / 2)); canvas.drawRect(mBackgroundRectF, mBorderPaint);
Now it looks right:
after
Yxp
source share