1

I want to draw text below circle in canvas. Following is my code but text is drawn above circle.

 canvas.drawCircle(getWidth() / 2, getHeight() / 2, radius, paint);
 canvas.drawText(text, 0, (radius*2), textPaint);
Dhrupal
  • 1,863
  • 1
  • 23
  • 38

1 Answers1

1

Looking at it properly you need to set the y value based on height of the canvas, same way you did the circle, then adjust it to be Below based on radius.

canvas.drawCircle(getWidth() / 2, getHeight() / 2, radius, paint);
canvas.drawText(text, 0, (getHeight() / 2) + radius, textPaint);

One thing that may be confusing you is that the origion is the top left. And that increase in Y is downwards

You may need to add a few extra pixels based on text height. so (getHeight() / 2) + radius + 20

IAmGroot
  • 13,760
  • 18
  • 84
  • 154
  • See this regarding screen/canvas coordinates. http://stackoverflow.com/questions/11483345/how-do-android-screen-coordinates-work – IAmGroot Aug 03 '16 at 08:56