我的应用程序在 Google Play 上发布并且显然在除 4.0 以上版本以外的所有 Android 版本上都运行良好。
这是我的 Android 4.0 HTC 手机的屏幕截图:
这就是我在 Nexus 7、Android 4.2.1 上得到的结果(模拟器中的行为相同):
我看到使用 canvas.drawText()
用来绘制文字的Paint是:
paint = new Paint();
paint.setAntiAlias(true);
paint.setColor(color); //some color
paint.setTextSize(size); //some size
paint.setTypeface(Typeface.defaultFromStyle(Typeface.BOLD));
paint.setTextAlign(Align.CENTER);
在logCat(4.2.1模拟器)中我看到了很多
12-18 20:42:21.096: W/Trace(276): Unexpected value from nativeGetEnabledTags: 0
我在 list 中使用这些设置:
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="8" />
最佳答案
经过大量谷歌搜索后,我回答了我自己的问题...
技巧在于对用于绘制文本的 Paint 对象使用 setLinearText(true)
。现在,一切看起来都很棒。
paint = new Paint();
paint.setAntiAlias(true);
paint.setColor(color);
paint.setTextSize(size);
paint.setTypeface(Typeface.defaultFromStyle(Typeface.BOLD));
paint.setTextAlign(Align.CENTER);
paint.setLinearText(true);
这里是拯救我一天的链接:
http://gc.codehum.com/p/android/issues/detail?id=39755
我希望它能帮助到别人。
最好的情况下文本还没有呈现:
编辑 (14/01/2013)
我仍然面临 kering 问题(仅在 4.2.1 上)。请在这里查看我的其他问题:
Android 4.2.1 wrong character kerning (spacing)
编辑 (05/02/2013)
我看到另一个项目也有同样的问题。查看下面的链接:
http://mindtherobot.com/blog/272/android-custom-ui-making-a-vintage-thermometer/
如果您在 Nexus 4.2.1(或模拟器 Android 4.2)上运行示例,您会得到相同的“奇怪”文本...
编辑 (20/02/2013)
找到了一个不使用setLinearText(true)
的解决方法,看这里:
关于Nexus 7 上的 Android 4.2 : canvas. drawText() 无法正常工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13941270/