在画布上要绘制测量文本高度(安卓) [英] Measuring text height to be drawn on Canvas ( Android )

查看:189
本文介绍了在画布上要绘制测量文本高度(安卓)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

任何直接的方式来衡量文字的高度? 我现在做的方法是使用涂料的measureText()来获得的宽度,然后通过反复试验找到一个值,以得到一个近似的高度。我也一直在茫然的的FontMetrics,但所有这些看起来像吸吮近似的方法。

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.

我想扩展事情不同的分辨率。我能做到这一点,但我结束了令人难以置信的详细code,有很多的计算,以确定相对大小。我讨厌它!必须有一个更好的办法。

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.

什么办法,一件事的时间:谢谢

Any way, one thing at a time: Thanks.

推荐答案

什么<一href="http://developer.android.com/reference/android/graphics/Paint.html#getTextBounds%28char%5B%5D,%20int,%20int,%20android.graphics.Rect%29">Paint.getTextBounds()

这篇关于在画布上要绘制测量文本高度(安卓)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆