Dhrupal Dhrupal - 4 months ago 28
Android Question

Draw text below Circle

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);

Answer

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