5

複数の言語にローカライズされたプログラムがあります。Android 4.x では問題なく動作しますが、Android 2.3.x ではフォント レンダリングの問題があります。これを再現する小さな例を次に示します。どんな助けでも大歓迎です。

主な活動のレイアウト。ここでは特別なことは何もありません。2 つの TextView ビューのみ:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:padding="10dp" >

    <TextView
        android:id="@+id/text_view1"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="80dp"
        tools:context=".MainActivity" />

    <TextView
        android:id="@+id/text_view2"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="80dp"
        tools:context=".MainActivity" />

</LinearLayout>

主な活動:

package com.font_test;

import android.app.Activity;
import android.graphics.Typeface;
import android.os.Bundle;
import android.widget.TextView;

public class MainActivity extends Activity {

    private static final String TEXT = 
            "\u0440\u0443\u0441\u0441\u043A\u0438\u0439" + 
            "\n" + 
            "pyccknn";

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        // Set textview 1
        final Typeface typeface1 = Typeface
                .createFromAsset(getAssets(), "fonts/chelsea.ttf");
        final TextView tv1 = (TextView) findViewById(R.id.text_view1);
        tv1.setTypeface(typeface1);
        tv1.setTextSize(40);
        tv1.setBackgroundColor(0x280000ff);
        tv1.setText(TEXT);

        // Set textview 2
        final Typeface typeface2 = Typeface.SANS_SERIF;
        final TextView tv2 = (TextView) findViewById(R.id.text_view2);
        tv2.setTypeface(typeface2);
        tv2.setTextSize(40);
        tv2.setBackgroundColor(0x280000ff);
        tv2.setText(TEXT);
    }
}

カスタム フォント chelsea.ttf はhttp://www.dafont.com/chelsea.fontから入手できます。特別なことは何もありません。他のフォントでも再現できます。

TEXT 文字列には 2 行が含まれます。最初の行には chelsea フォントにない Unicode 文字が含まれ、2 行目にはチェルシー フォントに含まれる文字が含まれます。最初のテキスト ビューはカスタム フォントでレンダリングされ、2 番目のテキスト ビューはストック サン セリフ フォント (TEXT のすべての Unicode 文字を含む) でレンダリングされます。

Android 4.x では正しくレンダリングされ、必要に応じてストック フォントにフェールオーバーされます。

ここに画像の説明を入力

ただし、Android 2.3.x では正しくレンダリングされません。ストックフォントにフォールバックしますが(良い)、奇妙なメトリックを使用しているため、文字間隔が大きすぎます。

ここに画像の説明を入力

それを修正する方法はありますか?必要に応じて、醜い回避策を受け入れます。

4

0 に答える 0