Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I am creating a custom view by extending android.view.View.

Now, I need to draw a rounded rectangle on API level below 21. Android has a built in method name,drawRoundRect(float left, float top, float right, float bottom, float rx, float ry, Paint paint) in android.graphics.Canvas, but It doesn't support API below 21, but I need to draw this on API 16. How can I achieve that?

Thanks in advance

like image 248
touhid udoy Avatar asked Dec 24 '22 03:12

touhid udoy


1 Answers

I got my solution after all!

Although 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) which is added in API level 1 that can be used instead.

Thanks pskink for the guide.

Example:

Rectf rectf= new Rectf(left, top, right, bottom);
canvas.drawRoundRect(rectf,rx,ry, mPaint);
like image 73
touhid udoy Avatar answered Dec 26 '22 00:12

touhid udoy