开发者

Adjusting Font Size to Fit, Paint.measureText returns too small a value

开发者 https://www.devze.com 2023-01-23 09:20 出处:网络
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

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 invisi开发者_JAVA百科ble 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?


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

0

精彩评论

暂无评论...
验证码 换一张
取 消