如何在 Canvas 上的 API 21 级以下绘制圆角矩形

How to Draw Rounded Rectangle in API Level below 21 on a Canvas

我正在通过扩展 android.view.View 创建自定义视图。

现在,我需要在 21 以下的 API 层上绘制一个圆角矩形。Android 有一个内置方法名称,drawRoundRect(float left, float top, float right, float bottom, float rx, float ry, Paint paint)android.graphics.Canvas 中,但是它不支持 21 以下的 API,但是 我需要在 API 16 上绘制它。我怎样才能做到这一点?

提前致谢

终于找到解决办法了!

虽然 drawRoundRect(float left, float top, float right, float bottom, float rx, float ry, Paint paint) is added in API level 21, there is another method, drawRect (RectF rect,Paint paint) 添加在 API 级别 1 中,但可以代替使用。

感谢 pskink 的指导。

示例:

Rectf rectf= new Rectf(left, top, right, bottom);
canvas.drawRoundRect(rectf,rx,ry, mPaint);