cdsap
cdsap

Reputation: 133

Number inside circle

What is the best way for draw a number inside circle drawed on canvas by drawCircle?

Then this circle can be dragged by user, when circle is empty I don´t have problems.

Upvotes: 0

Views: 741

Answers (1)

yoah
yoah

Reputation: 7230

This will draw text centered at centerX, centerY

Rect rect = new Rect();

paint.getTextBounds(text, 0, text.length(), rect);
float x = centerX - rect.width() / 2;
FontMetrics fm = paint.getFontMetrics();
float y= centerY - (fm.descent + fm.ascent) / 2;
canvas.drawText(text, x, y, paint);

Upvotes: 1

Related Questions