【问题标题】:Android Custom Font rendering issueAndroid自定义字体渲染问题
【发布时间】:2017-08-07 06:10:47
【问题描述】:

我正在尝试更改我的列表视图字体。我创建了assets/fonts 文件夹。我在这个文件夹中添加了OpenSans-Regular.ttf。我在我的适配器类中添加了typeface 行。 适配器:

public class Adapter extends BaseAdapter {

    List<String> listFunds;
    Typeface typeface;


    Context mContext;

    public Adapter(Context mContext, List<String> listFunds) {
        this.mContext = mContext;
        this.listFunds = listFunds;

    }

    public int getCount() {
        return listFunds.size();
    }

    public Object getItem(int arg0) {
        return null;
    }

    public long getItemId(int position) {
        return position;
    }

    public View getView(int position, View arg1, ViewGroup viewGroup) {

        LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        View row = inflater.inflate(R.layout.list_row, viewGroup, false);
        TextView textView = (TextView) row.findViewById(R.id.textView);

        textView.setText(listFunds.get(position));
        typeface = Typeface.createFromAsset(mContext.getAssets(), "fonts/"+"OpenSans-Regular.ttf");
        textView.setTypeface(typeface);


        return row;
    }
}

但是,字体看起来不像它应该的那样。我尝试了很多字体,但没有任何改变。

我的应用看起来像这样:

但是,字体应该是这样的

【问题讨论】:

  • 您是在物理设备上还是在模拟器上运行应用程序?
  • 在 Android 模拟器上。 @乔纳斯
  • 请注意,众所周知,模拟器在正确渲染图形方面存在问题。我强烈建议您在物理设备上运行该应用程序。
  • 谢谢!问题出在模拟器上。我正在使用 GenyMotion,字体现在看起来不错:) @Jonas

标签: android fonts


【解决方案1】:

我建议你把这个typeface = Typeface.createFromAsset(mContext.getAssets(), "fonts/"+"OpenSans-Regular.ttf"); 放在构造函数中以提高效率。它也可能是导致您出现问题的原因。或者可能更改您正在使用的字体文件,对我来说,它看起来可能与英文字符的语言不同。

【讨论】:

  • 感谢您的快速回复!我也试过了。正如@Jonas 所说,模拟器是个问题。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-11-08
  • 2017-07-06
  • 1970-01-01
  • 2015-09-12
  • 2015-05-12
  • 1970-01-01
相关资源
最近更新 更多