7

Google Playに公開されているアプリケーションで重大な問題に直面していますが、> 4.0以外のAndroidのすべてのバージョンで問題なく動作しているようです。Nexus 7のAndroid 4.2:canvas.drawText()が正しく動作しない

これは私のアンドロイド4.0 HTCの携帯電話からscreenshootです:

enter image description here

そして、これは私がネクサス7、アンドロイド4.2.1(エミュレータで同じ動作)で取得されるものです:

enter image description here

私はcanvas.drawText()

を使用して描かれた各テキストに同じ動作を確認

テキストを描画するために使用される塗料は、次のとおりです。logCat(4.2.1エミュレータ)では

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

私はマニフェストでこれらの設定を使用

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

の多くを参照してください。

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

実際にはテキストサイズは0.175fで、backgroundCanvas.scale(getWidth()、getWidth()); –

答えて

14

私はグーグルの多くの後に自分の質問に答える...

トリックは、テキストの描画に使用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

私はそれがsomeonelse役立つことを願って。

テキストはまだ最高でレンダリングされていません。

enter image description here

編集(14/01/2013)

私はまだのみ4.2に(ケリングの問題に直面しています。 1)。同じ問題を抱えている、私は別のプロジェクトを参照してください

Android 4.2.1 wrong character kerning (spacing)

編集(2013年5月2日)

:ここに私の他の質問を参照してください。下のリンクを見てください:

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

あなたはネクサス4.2.1のサンプルを実行する場合(またはシミュレータのAndroid 4.2に)あなたが同じ「奇妙な」テキストを取得...

編集ないsetLinearText(true)を使用する回避策を(20/02/2013)

を発見、ここを見て:

Android 4.2.1 wrong character kerning (spacing)

+0

ありがとう、ありがとう、ありがとう!あなたは私を狂気から救った!これは最終的にsetLinearText(true)で動作します。私は彼らが開発者のためのこれらのAPIの変更をより良く文書化したいと思います。 4.2.1で働くには2週間かかりました。 Grrr .... – ssuperz28

+0

私はこの問題で一人ではないことを嬉しく思っています...ご覧のとおり、文字のカーニングは間違っているようです(文字間隔は0です)。同じ問題がありますか?その他の質問はこちら:http://stackoverflow.com/questions/13974129/android-4-2-1-worng-character-kerning-spacing –

0

Android 4のデフォルトは「ハードウェアアクセラレーションオン」です。これで描画関数の一部が正しく動作しません。どのファイルが正確かは分かりませんが、マニフェストファイルでHardware Accelerationをオフにして、違いがあるかどうかを確認してください。

もちろん、これは原因ではないかもしれませんが、試してみる価値があります。

+0

ありがとうございます。 Unfortunatelly tag android:hardwareAcceleratedはAndroid 3.0の下で認識されないので、私のアプリケーション(Android 2.3.3)には使用できません。 –

+0

Android 3または4に対してコンパイルすることができます。サポートしていないバージョンでは無視されます。 (マニフェストファイル以外のプロジェクトビルドターゲットを変更してください) – Kuffs

+0

OK、Android SDK 3.2、android:hardwareAccelerated = "false"を使用して同じ問題を再コンパイルしました。 –

1

私は同様の問題を抱えていました。私はこの2つの方法を作ったので、カスタム文字間隔で表示しようとしました。

/** 
* Draws a text in the canvas with spacing between each letter. 
* Basically what this method does is it split's the given text into individual letters 
* and draws each letter independently using Canvas.drawText with a separation of 
* {@code spacingX} between each letter. 
* @param canvas the canvas where the text will be drawn 
* @param text the text what will be drawn 
* @param left the left position of the text 
* @param top the top position of the text 
* @param paint holds styling information for the text 
* @param spacingPx the number of pixels between each letter that will be drawn 
*/ 
public static void drawSpacedText(Canvas canvas, String text, float left, float top, Paint paint, float spacingPx){ 

    float currentLeft = left; 

    for (int i = 0; i < text.length(); i++) { 
     String c = text.charAt(i)+""; 
     canvas.drawText(c, currentLeft, top, paint); 
     currentLeft += spacingPx; 
     currentLeft += paint.measureText(c); 
    } 
} 

/** 
* returns the width of a text drawn by drawSpacedText 
*/ 
public static float getSpacedTextWidth(Paint paint, String text, float spacingX){ 
    return paint.measureText(text) + spacingX * (text.length() - 1); 
} 
関連する問題