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

问题描述

在使用画布的drawText()方法,我看到了不同的呈现在Android 4.2.1。

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

低于4.2:

有关的Andr​​oid 4.2.1(Nexux 7)我得到:

For Android 4.2.1 (Nexux 7) I get:

正如你可以看到文本的功耗的很紧。似乎是在4.2.1推出了字距问题。用于绘制文本涂料是没有什么特别的:

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(真)我得到一个奇怪的结果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:

Android 4.2在Nexus 7:canvas.drawText()无法正常工作

编辑:

这个奇怪的行为已经被上报给Android团队:<一href="http://$c$c.google.com/p/android/issues/detail?id=39755">http://$c$c.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&LT; 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.

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

08-30 07:12