Ad

How To Center A Text In Canvas Vertically

- 1 answer

I managed to center a text horizontaly with Align.CENTER. But it doesn't center the text vertically .

paint.setTextAlign(Align.CENTER);
canvas.drawText(text, fx, fy, paint);

How to center the text vertically ?

Ad

Answer

Align.CENTER is for horizontal alignment. If you want to center vertically, you need to find the maximum height for the text and then position vertically within canvas by translating vertically using canvas.translate

Ad
source: stackoverflow.com
Ad