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

守給你的承諾、 提交于 2019-12-25 04:45:12

问题


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?


回答1:


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



来源:https://stackoverflow.com/questions/4064279/adjusting-font-size-to-fit-paint-measuretext-returns-too-small-a-value

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!