使用自定义字体的画布上的Java的Andr​​oid画 [英] Using of custom typeface for drawing on canvas Java Android

查看:118
本文介绍了使用自定义字体的画布上的Java的Andr​​oid画的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有我已加载的字样对象Typeface.createFromAsset(...)的自定义字体。我需要从这个字体用在画布上煤焦code 37绘图1 symbom。我用这个code:

 的String =将String.valueOf(((char)的37));

涂料粉刷=新的油漆();
paint.setTypeface(mNoteTypeface);
paint.setTextSize(30);

canvas.drawText(S,20,20,油漆);
 

但结果并不好。我有计划观看字体和一种让我明白了: http://imagepost.ru/?v=qzvcgsbbxkldahdxuptuuvuyyugqlx.jpg

帮助我创造了code,我很不高兴。

解决方案

code所示是正确的。确保 mNoteTypeface 包含自定义字体。寻找:

  1. 在字体文件是在资产\字体项目的文件夹中。
  2. 字体文件是大小写敏感的,字型\ deco.ttf不会为<$​​ C $ C>Deco.ttf工作文件:
  

paint.setTypeface(Typeface.createFromAsset(getAssets(),                       字体/ Deco.ttf));

I have a custom typeface which I have loaded in Typeface object with Typeface.createFromAsset(...). I need to drawing 1 symbom from this typeface with char-code 37 on canvas. I use this code:

String s=String.valueOf(((char)37));

Paint paint=new Paint();
paint.setTypeface(mNoteTypeface);
paint.setTextSize(30);

canvas.drawText(s, 20, 20, paint);

But result doesn't be good. I have the program for viewing fonts and one showed me that: http://imagepost.ru/?v=qzvcgsbbxkldahdxuptuuvuyyugqlx.jpg

Help me to create a code, I'm very upset.

解决方案

code shown is correct. Make sure mNoteTypeface contains custom font. Look for:

  1. font file is in assets\fonts folder of project.
  2. font files are case sensitive, "fonts\deco.ttf" will not work for "Deco.ttf" file:

paint.setTypeface(Typeface.createFromAsset(getAssets(), "fonts/Deco.ttf"));

这篇关于使用自定义字体的画布上的Java的Andr​​oid画的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆