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

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

问题描述

我面对我的应用程序的一个严重问题,发表了关于谷歌播放,显然,除了> 4.0做工精细上的所有版本的Andr​​oid。

这是从我的Andr​​oid 4.0的HTC手机screenshoot:

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

我看到相同的行为使用绘制每个文本 canvas.drawText()

用于绘制文本的涂料是:

 颜料=新的油漆();
paint.setAntiAlias​​(真正的);
paint.setColor(颜色); //一些色彩
paint.setTextSize(大小); //一些大小
paint.setTypeface(Typeface.defaultFromStyle(Typeface.BOLD));
paint.setTextAlign(Align.CENTER);
 

在LogCat中(4.2.1仿​​真器),我看到了很多

  12-18 20:42:21.096:W /跟踪(276):从nativeGetEnabledTags意外的值:0
 

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

 <使用-SDK
        安卓的minSdkVersion =8
        机器人:targetSdkVersion =8/>
 

解决方案

我很多谷歌上搜索后,回答我的问题...

诀窍包括在使用 setLinearText(真) 作为用于绘制文本的绘制对象。现在,一切看起来不错。

 颜料=新的油漆();
paint.setAntiAlias​​(真正的);
paint.setColor(颜色);
paint.setTextSize(大小);
paint.setTypeface(Typeface.defaultFromStyle(Typeface.BOLD));
paint.setTextAlign(Align.CENTER);
paint.setLinearText(真正的);
 

下面,节省了我一天的链接:

<一个href="http://gc.$c$chum.com/p/android/issues/detail?id=39755">http://gc.$c$chum.com/p/android/issues/detail?id=39755

我希望它可以帮助someonelse。

该文本不是在最好的呈现尚未:

编辑(14/01/2013)

我仍面临(仅限于4.2.1)一开云集团的问题。请看看我其他的问题在这里:

<一个href="http://stackoverflow.com/questions/13974129/android-4-2-1-worng-character-kerning-spacing">Android 4.2.1错误的字符字距(间距)

编辑(2013年5月2日)

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

<一个href="http://mindtherobot.com/blog/272/android-custom-ui-making-a-vintage-thermometer/">http://mindtherobot.com/blog/272/android-custom-ui-making-a-vintage-thermometer/

如果您运行的Nexus 4.2.1样品(或模拟器的Andr​​oid 4.2),你会得到相同的奇怪的文字...

编辑(20/02/2013)

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

<一个href="http://stackoverflow.com/questions/13974129/android-4-2-1-worng-character-kerning-spacing">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)

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

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