4

我有一个基于印地语内容的 android 应用程序,并使用了来自 Android API 16 SDK 的 devangiri 字体并重命名为hindi.ttf。文本在 API 级别 16 和 17 上呈现良好,但在 Android API 级别 15 及更低级别时会被撕裂。

有什么原因我可以在不删除对较低 API 级别的支持的情况下解决这个问题。我设置 textview 的代码是:

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

public class Prayer extends Activity {

    // TextSwitcher vs;
    GestureDetector gestureDetector;
    static Tips tip = null;
    static StringBuilder quesString = null;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.prayer);

        TextView tv1 = (TextView) findViewById(R.id.textView1);
        Typeface tf = Typeface.createFromAsset(getAssets(), "fonts/hindi.ttf");
        tv1.setTypeface(tf);
        tv1.setText("श्री");
        tv1.setPaintFlags(tv1.getPaintFlags() | Paint.SUBPIXEL_TEXT_FLAG);
    }
}

布局 XML:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#C5C6E1"
    tools:context=".Prayer" >
            <TextView
                android:id="@+id/textView1"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content" >
            </TextView>
</RelativeLayout>

当前的: 在此处输入图像描述

预期的: 在此处输入图像描述

4

2 回答 2

5

I faced exactly similar issue when I was developing an Hindi app. However, the error resolved when I changed the font files.

Also, IMHO the device simply replaces UTF-8 symbols in text with corresponding symbols in font files. In this case, its showing a completely different symbol altogether. So, the problem should be with font files.

Give me your e-mail in case you want to use my font files.

于 2013-04-23T05:49:53.543 回答
3

为了支持印地语,我向后移植了DroidSansDevanagari-Regular.ttfJellybean 中添加的字体。您可以在 SDK 目录下找到所有 Jellybean Android 字体:

/<Android SDK Dir>/platforms/android-16/data/fonts

如果您在 4.0.2 上仍然看到撕裂,您可以尝试:

tv1.setPaintFlags(tv1.getPaintFlags() | Paint.SUBPIXEL_TEXT_FLAG);

设置动态 textSize 时,请使用:

tv1.setTextSize(TypedValue.COMPLEX_UNIT_PX, getResources().getDimensionPixelOffset(R.dimen.questionTEXT));
于 2013-04-19T19:02:24.443 回答