tags:

views:

78

answers:

2

How to find the exact pixel center of a String? I need this for drawing onto a canvas.

SOLVED

float ty = ((-mTextBrush.ascent() + mTextBrush.descent())/4);

Add this value to the y axis when you draw.

ie.

canvas.drawText(text, cx, cy+ty, mTextBrush);

where cx and xy are your center points

+1  A: 

Use the paint.measureText( "String" ), it will give the number of pixels required to display the string.

Karan
A: 

It's not the answer but probably can solve your problem.

Paint has setTextAlign method. If you set

paint.setTextAlign(Paint.Align.CENTER);

drawText(text, x, y, paint) will paint text with the (x,y) in the center.

skyman
It is possible to find the Vertical center?
jax