4

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

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

提前致谢

4

1 回答 1

10

毕竟我得到了解决方案!

虽然drawRoundRect(float left, float top, float right, float bottom, float rx, float ry, Paint paint)是在 API 级别 21 中添加的,但还有另一种方法,drawRect (RectF rect,Paint paint)即在 API 级别 1 中添加的可以替代使用的方法。

感谢pskink的指导。

例子:

Rectf rectf= new Rectf(left, top, right, bottom);
canvas.drawRoundRect(rectf,rx,ry, mPaint);
于 2018-10-28T14:21:47.987 回答