Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Draw square with rounded corners

I am able to draw a rect with sharp edges, now I need to make the sharp edges to rounded.

How to do that?

This is my code:

 public void drawShape(Canvas canvas, Renderer renderer, float x, float y,
      int seriesIndex, Paint paint) {
    float halfShapeWidth = shape_width / 2;
    canvas.drawRect(x , y - halfShapeWidth, x + SHAPE_WIDTH, y + halfShapeWidth, paint);
   }

How to make this rounded rect by passing the same parameters?

like image 338
Goofy Avatar asked Feb 07 '13 09:02

Goofy


2 Answers

Ok i solved it myself by using this code:

RectF r = new RectF(1,2,3,4);
canvas.drawRoundRect(r, 0, 0, mPaint);

Hope it will help others.

like image 106
Goofy Avatar answered Nov 15 '22 05:11

Goofy


You can use drawRoundRect

You will need to pack the position and the dimensions in a RectF before you can call this function.

like image 30
gulyan Avatar answered Nov 15 '22 05:11

gulyan