【问题标题】:Horizontal stripes over a custom font in AndroidAndroid中自定义字体上的水平条纹
【发布时间】:2013-01-03 11:27:31
【问题描述】:

我正在尝试在我的文本中添加自定义字体,但问题是文本上出现垂直条纹。它们不在字体中,而且问题似乎只出现在某些 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):

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

【问题讨论】:

    标签: android image fonts appearance typeface


    【解决方案1】:

    这不是一个完美的解决方案,但我能够通过对文本应用假粗体来修复垂直间隙。这意味着 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);
    

    【讨论】:

      猜你喜欢
      • 2012-06-26
      • 1970-01-01
      • 2017-10-05
      • 2014-03-23
      • 1970-01-01
      • 1970-01-01
      • 2011-08-07
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多