Android 4.2.1 错误字符字距调整(间距) [英] Android 4.2.1 wrong character kerning (spacing)

查看:32
本文介绍了Android 4.2.1 错误字符字距调整(间距)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当使用 CanvasdrawText() 方法时,我在 Android 4.2.1 上看到了不同的渲染.

When using Canvas and drawText() method I see a different rendering on Android 4.2.1.

低于 4.2:

对于 Android 4.2.1 (Nexux 7) 我得到:

For Android 4.2.1 (Nexux 7) I get:

如您所见,文本Consumption 非常紧张.好像是 4.2.1 引入的字距调整问题.用于绘制文本的 Paint 没什么特别的:

As you can see the text Consumption is very tight. Seems to be a kerning problem introduced in 4.2.1. The Paint used to draw text is nothing special:

titlePaint = new Paint();
titlePaint.setAntiAlias(true);
titlePaint.setColor(0xffffffff);
titlePaint.setTextSize(0.125f);
titlePaint.setTypeface(Typeface.defaultFromStyle(Typeface.BOLD));
titlePaint.setTextAlign(Align.CENTER);
titlePaint.setLinearText(true);

如果我不使用 titlePaint.setLinearText(true) 我会在 4.2.1 上得到一个奇怪的结果,正如你在那里看到的:

If I don't use titlePaint.setLinearText(true) I get a strange result on 4.2.1 as you can see there:

Nexus 7 上的 Android 4.2:画布.drawText() 无法正常工作

这种奇怪的行为已报告给 Android 团队:http://code.google.com/p/android/issues/detail?id=39755 但这仍然不是官方"问题.

This strange behaviour has been reported to the Android team: http://code.google.com/p/android/issues/detail?id=39755 but it's still not a "official" issue.

编辑 (2):

一些谣言声称问题在于 textSize

1.0f...

Some rumors claim that the problem is a textSize < 1.0f...

推荐答案

我目前正在使用的解决方法:

Workaround, that I'm currently using:

scalePaint.setTextSize(1.5f);

然后,在 onDraw 方法中:

then, in onDraw method:

canvas.save();
canvas.scale(0.01f, 0.01f);
canvas.drawText(""+i, 0.5f*100, 0.8f*100, scalePaint);                  
canvas.restore();

正如你所看到的,我正在重新调整文本的位置,所以它是它应该在的位置.

As you can see, I'm rescaling back the position of the text, so it's where it's supposed to be.

这篇关于Android 4.2.1 错误字符字距调整(间距)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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