Nexus 7 上的 Android 4.2:canvas.drawText() 无法正常工作 [英] Android 4.2 on Nexus 7: canvas.drawText() not working correctly

查看:32
本文介绍了Nexus 7 上的 Android 4.2:canvas.drawText() 无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 Google Play 上发布的应用程序遇到了严重问题,并且显然在所有版本的 Android 上运行良好,除了 > 4.0.

这是我的 Android 4.0 HTC 手机的屏幕截图:

这是我在 Nexus 7、Android 4.2.1 上得到的(模拟器中的行为相同):

对于使用 canvas.drawText()

绘制的每个文本,我看到了相同的行为

用于绘制文本的 Paint 是:

paint = new Paint();Paint.setAntiAlias(true);Paint.setColor(颜色);//一些颜色Paint.setTextSize(size);//一些大小Paint.setTypeface(Typeface.defaultFromStyle(Typeface.BOLD));Paint.setTextAlign(Align.CENTER);

在logCat(4.2.1模拟器)中我看到了很多

12-18 20:42:21.096:W/Trace(276):来自 nativeGetEnabledTags 的意外值:0

我在清单中使用这些设置:

 

解决方案

经过大量谷歌搜索后,我回答了我自己的问题...

技巧在于对用于绘制文本的 Paint 对象使用 setLinearText(true).现在,一切看起来都很棒.

paint = new Paint();Paint.setAntiAlias(true);Paint.setColor(颜色);Paint.setTextSize(size);Paint.setTypeface(Typeface.defaultFromStyle(Typeface.BOLD));Paint.setTextAlign(Align.CENTER);Paint.setLinearText(true);

这里是拯救我一天的链接:

已编辑 (05/02/2013)

我看到另一个项目有同样的问题.看下面的链接:

http://mindtherobot.com/博客/272/android-custom-ui-making-a-vintage-thermometer/

如果您在 Nexus 4.2.1(或模拟器 Android 4.2)上运行示例,您会得到相同的奇怪"文本...

已编辑 (20/02/2013)

找到一个不使用setLinearText(true)的解决方法,看这里:

Android 4.2.1 错误的字符字距调整(间距)

I'm facing a serious issue with my Application, published on Google Play and apparently working fine on all versions of Android except for > 4.0.

This is a screenshoot from my Android 4.0 HTC phone:

And this is what I get on Nexus 7, Android 4.2.1 (same behaviour in the emulator):

I see the same behaviour for each text drawn using canvas.drawText()

the Paint used to draw text is:

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);

In the logCat (4.2.1 emulator) I see a lot of

12-18 20:42:21.096: W/Trace(276): Unexpected value from nativeGetEnabledTags: 0

I use these settings in the manifest:

 <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="8" />

解决方案

I answer my own question after a lot of googling...

The trick consist in the use of setLinearText(true) for the Paint object used for drawing the text. Now, everything looks great.

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);

Here the link that saves my day:

http://gc.codehum.com/p/android/issues/detail?id=39755

I hope it can help someonelse.

The text is not rendered at the best yet:

Edited (14/01/2013)

I'm still facing a kering problem (only on 4.2.1). Please see my other question here:

Android 4.2.1 wrong character kerning (spacing)

Edited (05/02/2013)

I see another projects has the same problem. Look at the link below:

http://mindtherobot.com/blog/272/android-custom-ui-making-a-vintage-thermometer/

If you run the sample on Nexus 4.2.1 (or in the simulator Android 4.2) you get the same "strange" text...

Edited (20/02/2013)

Found a workaround that not uses setLinearText(true), look here:

Android 4.2.1 wrong character kerning (spacing)

这篇关于Nexus 7 上的 Android 4.2:canvas.drawText() 无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆