简体   繁体   English

Paint.setTextSize()的参数代表什么?

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

I'm trying to write a resolution independent Android game. 我正在尝试编写独立于Android的解决方案。 I have some text I want to render onto the canvas and use Paint.setTextSize(...) to set the size of the text. 我有一些文本要渲染到画布上,并使用Paint.setTextSize(...)来设置文本的大小。 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 (ie 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. 我知道布局和textview小部件可能有所帮助,但因为它是一个游戏,我需要在演示文稿中有很大的灵活性。

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?). 根据经验,它是像素(真实像素,不是倾角:我尝试过Galaxy Tab 10.1“(mdpi)和240 dpi(hdpi)的模拟器,结果几乎相同......实际上,字体的颜色小了两个像素模拟器,虽然getFontSpacing()返回相同的数字;下面的结果是Galaxy Tab。我正在绘制一个位图...我认为它与View的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). 我将文本大小设置为40并且getFontSpacing()返回46.使用屏幕上的网格我发现大写字母的高度大约是29像素高,从“T”顶部到底部的距离是“g”约为39个像素,从ÁccentedÍ的顶部到“g”的底部的距离是48个像素(包括)。 The typeface was Typeface.defaultFromStyle(Typeface.NORMAL) . 字体是Typeface.defaultFromStyle(Typeface.NORMAL)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM