Skip to content Skip to sidebar Skip to footer

Android: Roundrectshape: Modify Corner Radii

I have a RoundRectShape that is drawn in a View's onDraw() function. The corners of this shape are modified by any drag actions on this view through an overridden onTouchEvent fun

Solution 1:

I think you don't need to use RoundRectShape at all. RoundRectShape is immutable so the only way to change its values is to use reflection. You can easily accomplish the same drawnings by calling Canvas.drawRoundRect(RectF rect, float rx, float ry, Paint paint) method directly without using RoundRectShape. Or you can look at RoundRectShapeimplementation and just use its code in your onDraw() method.

EDIT: The comments about RoundRectShape not being the right way to go and looking at the implementation were right. Following the implementation found a call to:

mPath.addRoundedRect() 

which has a variation allowing a float of corner radii as the input (Path.addRoundRect)

In answering the question:

Use a path instead of a shape as the variable and draw the new Rounded Rectangle to the path when necessary

Post a Comment for "Android: Roundrectshape: Modify Corner Radii"