以 pt 为单位的文本大小在 Samsung Galaxy S2 i9108 上不起作用
我从头开始创建了一个 Hello World 应用程序。它的布局包含一个 TextView,它没有指定 android:textSize
值,它在真实设备的屏幕上显示良好。我又添加了一些,它们明确指定了以磅为单位的文本大小,它们都显得非常非常小,几乎看不见。
<!-- Without textSize given. This one shows fine. -->
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello" />
<!-- These have a different size, in points. They are invisible. -->
<TextView
android:textSize="12pt"
android:text="Hello world, 12pt"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
<TextView
android:textSize="16pt"
android:text="Hello world, 16pt"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
作为进一步的测试,我将一些尺寸放入 res.values
文件夹中,并以编程方式访问它们:
<resources>
<dimen name="fontSize">8pt</dimen>
<dimen name="height">60dp</dimen>
</resources>
......
......
i = getResources().getDimensionPixelSize(R.dimen.fontSize); // returns 1
i = getResources().getDimensionPixelSize(R.dimen.height); // returns 90
Samsung Galaxy S2 i9108 的密度为 240dpi,因此 60dp 相当于 90 像素。但对于所有以磅为单位的大小,它们似乎都被转换为非常小的值。有人有想法吗?提前致谢。
此应用程序有一个 minSDKVersion="10"
,这就是 i9108。所以我认为这不会成为问题。而且,这个应用程序在模拟器上运行良好,但在真实设备上运行不佳。
(我手头没有真正的设备,测试很困难。所以到目前为止我还没有做很多测试。)
有人有想法吗?先感谢您。
I created a Hello World app from scratch. Its layout contains one TextView, which did not specify a android:textSize
value, it shows fine on screen on a real device. I added a few more, which explicitly specify text sizes in points, they all appear very very very small, almost invisible.
<!-- Without textSize given. This one shows fine. -->
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello" />
<!-- These have a different size, in points. They are invisible. -->
<TextView
android:textSize="12pt"
android:text="Hello world, 12pt"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
<TextView
android:textSize="16pt"
android:text="Hello world, 16pt"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
As a further test, I put a few sizes in the res.values
folder and access them programmatically:
<resources>
<dimen name="fontSize">8pt</dimen>
<dimen name="height">60dp</dimen>
</resources>
......
......
i = getResources().getDimensionPixelSize(R.dimen.fontSize); // returns 1
i = getResources().getDimensionPixelSize(R.dimen.height); // returns 90
Samsung Galaxy S2 i9108's density is 240dpi, so 60dp equates to 90 pixel is expected. But for all sizes in points, they seem to be translated to very small values. Does anybody have an idea? Thanks in advance.
This app has a minSDKVersion="10"
, which is what i9108 is. So I don't think this would be a problem. And, this app runs fine on emulator, but not on a real device.
(I don't have the real device in hand, testing is tough. So I haven't done a lot of tests so far.)
Does anybody have an idea? Thank you in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
通过我的用户的帮助,我确认三星 Galaxy S2 i9108 有一个“错误”,即它无法正确转换 pt 测量值。至于dp和sp,它们的翻译是正确的。我不想花时间解释为什么 pt 不正确,我们只是将所有字体大小更改为 dp,或 sp,尚未决定。 (我们一开始没有使用 sp 是有原因的。)
这似乎只发生在 i9108 上,我让 i9100 的用户确认我们的应用程序在他们的手机上没问题。所以我认为这是 i9108 特有的问题。
非常感谢所有回复我的人。谢谢。
Through the help of my user, I confirmed that Samsung Galaxy S2 i9108 has a "bug" that it doesn't translate measurements in pt correctly. As for dp and sp, they are correctly translated. I don't want to spend time on why pt is incorrect, we'll just change all font sizes to dp, or sp, haven't decided yet. (We didn't use sp in the first place was for a reason.)
This seems to happen to i9108 only, I have users of i9100 confirm that our app was all right on their phones. So I assume this is a i9108-specific problem.
A big thank-you to all those who responded me. Thanks.
对于文本大小,建议使用
sp
单位度量,它与屏幕密度无关,也可以按字体大小缩放。有关更多信息: http://developer.android.com/guide /topics/resources/more-resources.html#Dimension
For text sizes it is recommended to use
sp
unit measure which is screen density independent and also can be scaled by font size.For more information: http://developer.android.com/guide/topics/resources/more-resources.html#Dimension