views:

417

answers:

1

Hi all!

Is there a method which returns the width ( in pixels ) of a text to be drawn on an Android canvas using the drawText() method according to the Paint used to draw it.

Thx.

+4  A: 

Have you looked at android.graphics.Paint.measureText(String txt)?

Marc Bernstein
Thanks this is it! I don't know why I skipped it.The purpose was to simply draw a text at the center of the screen.Anyway I just realized I could also have just used setTextAlign(Align.CENTER) on the Paint used to draw the text, it shifts the specified origin to the center of the drawn text.Thanks.
NioX5199