Search code examples
androidgraphicsviewandroid-canvas

Measuring text height to be drawn on Canvas ( Android )


Any straight forward way to measure the height of text? The way I am doing it now is by using Paint's measureText() to get the width, then by trial and error finding a value to get an approximate height. I've also been messing around with FontMetrics, but all these seem like approximate methods that suck.

I am trying to scale things for different resolutions. I can do it, but I end up with incredibly verbose code with lots of calculations to determine relative sizes. I hate it! There has to be a better way.


Solution

  • What about paint.getTextBounds() (object method)