1

我正在尝试在我的文本中添加自定义字体,但问题是文本上出现垂直条纹。它们不在字体中,而且问题似乎只出现在某些 Android 设备上。

这是我的文本视图

<TextView
    android:id="@+id/header"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:gravity="center_horizontal"
    android:layout_marginTop="4dip"
    android:layout_marginBottom="4dip"
    android:textColor="#00fff0"
    android:textSize="14sp"
    android:text="Header"/>

我在 onCreate() 函数中设置字体如下

((TextView) findViewById(R.id.header)).setTypeface(Typeface.createFromAsset(this.getAssets(), "bitbold2.ttf"));

当像这样初始化时在画布上绘制文本时也会出现同样的问题:

Typeface bitNanoFont = Typeface.createFromAsset(asset, "bitbold2.ttf");
Paint textPaint = new Paint();
textPaint.setARGB(255, 0, 255, 240);
textPaint.setTextSize(24);
textPaint.setTypeface(bitNanoFont);

并画成这样:

canvas.drawText("Text", 320, 50, textPaint);

生成的文本如下所示(TextView):

文本看起来像这样。

图像已放大,背景是彩色的,因为该图像是直接从应用程序中获取的。

4

1 回答 1

0

这不是一个完美的解决方案,但我能够通过对文本应用假粗体来修复垂直间隙。这意味着 Android 在字母上添加了一些额外的笔画,从而弥补了空白。

在文本视图上

Typeface font = Typeface.createFromAsset(asset, "bitbold2.ttf");
TextView tw = (TextView) findViewById(R.id.header);
tw.setTypeface(font);
tw.setPaintFlags(Paint.FAKE_BOLD_TEXT_FLAG);

在画布上

Typeface font = Typeface.createFromAsset(asset, "bitbold2.ttf");
Paint paint = new Paint();
paint.setTypeface(font);
paint.setFakeBoldText(true);
于 2013-01-06T10:42:06.433 回答