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

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

问题描述

任何直接的方法来测量文本的高度?我现在这样做的方法是使用 Paint 的 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.

我正在尝试针对不同的分辨率进行缩放.我可以做到,但我最终得到了令人难以置信的冗长代码,其中包含大量计算以确定相对大小.我恨它!必须有更好的方法.

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.

推荐答案

paint.getTextBounds()(对象方法)

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

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