调整字体大小以适合,Paint.measureText 返回的值太小

发布于 2024-09-30 04:19:12 字数 548 浏览 5 评论 0原文

我正在使用发布在 另一个线程,但它对我来说并不完全正确。 measureText() 调用返回的数字显然太小而无法显示字符串。当它找到适合文本的字体大小时,它确定的字体大小仍然太大。我觉得还有一些其他类型的填充或边距或其他一些不可见的东西正在贡献构成宽度的数学,从而导致差异。

例如...我想将我的 FontFitTextView 的文本设置为“10,000.25”

我的 FontFitTextView 的宽度是 96 像素,两侧填充 8px,所以我的可用宽度是 80 像素。对measureText() 的调用表示文本“10,000.25”的宽度为64 像素。这意味着当前字体大小应该足够小以显示整个字符串。然而,当字符串实际绘制在 TextView 上时,最后 2 个字符被截掉,我看到的只是“10,000”。而不是“10,000.25”

有什么想法吗?

I'm using the FontFitTextView that was posted in this other thread, but it isn't working exactly right for me. The measureText() call is returning a number that is obviously too small to display the string. When it runs through to find a font size that will allow the text to fit, the font size it settles on is still too big. I feel like there is some other kind of padding or margin or some other invisible that is contributing the math that makes up the width which is causing the discrepancy.

For example... I want to set the text of my FontFitTextView to be "10,000.25"

The width of my FontFitTextView is 96 pixels, with 8px padding on both sides, so my available width is 80 pixels. The call to measureText() says that the text "10,000.25" is 64 pixels wide. This means that the current font size should be small enough to display the entire string. However, when the string is actually drawn on the TextView the last 2 characters are chopped off and all I see is "10,000." instead of "10,000.25"

Any ideas?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

独夜无伴 2024-10-07 04:19:12

事实证明问题与模拟器有关。我将我的应用程序配置到我的 Android 设备,并且 FontFitTextView 按预期工作。

It turns out the problem was related to the emulator. I provisioned my app to my android device and the FontFitTextView worked as intended.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文