开发者

What does the parameter to Paint.setTextSize() represent?

I'm trying to write a resolution independent 开发者_如何学PythonAndroid game. I have some text I want to render onto the canvas and use Paint.setTextSize(...) to set the size of the text. What does the parameter represent? The height of the letters in pixels?

I'm not sure how to set this parameter based on the density or size of the screen either. I generally want my text to fill a certain rectangle of the screen as well as possible (i.e. I want the text to get as close to the full height of the rectangle without the width of the text going outside the rectangle) but I'm not sure how I would do this. I know layouts and textview widgets could help but as it's a game I need a lot of flexibility in the presentation.


Empirically, it's pixels (real pixels, not dip: I tried a Galaxy Tab 10.1" (mdpi) and an emulator at 240 dpi (hdpi), and the results were almost the same... actually, the font was two pixels smaller on the emulator, although getFontSpacing() returned the same number; results below are for the Galaxy Tab. I was drawing to a bitmap... I assume it's the same for a View's Canvas?).

I set the text size to 40 and getFontSpacing() returned 46. Using an on-screen grid I found that the height of a capital letter is about 29 pixels high, the distance from the top of a "T" to the bottom of a "g" is about 39 pixels, and the distance from the top of a Áccented Í to the bottom of a "g" is 48 pixels (inclusive). The typeface was Typeface.defaultFromStyle(Typeface.NORMAL).

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜