我的应用程序运行android冰淇淋三明治,在字体文件夹中导入roboto.ttf和roboto-bold.ttf字体并使用这些字体设置四个文本视图之后,滚动列表视图时非常(非常)慢。有谁知道优化性能的方法?是否有任何提高速度的提示和技巧?
我澄清在插入这些代码行之前它非常顺利:
Typeface roboto = Typeface.createFromAsset(activity.getAssets(), "fonts/Roboto-Regular.ttf");
Typeface robotobold = Typeface.createFromAsset(activity.getAssets(), "fonts/Roboto-Bold.ttf");
nome.setTypeface(robotobold);
mq.setTypeface(roboto);
citta.setTypeface(roboto);
prezzo.setTypeface(roboto);
descrizione.setTypeface(roboto);
我添加了可以帮助进行字体缓存的类:
public class TypefaceCache {
private final HashMap<String, Typeface> map;
private Context con;
public TypefaceCache(Context con) {
map = new HashMap<String, Typeface>();
this.con = con;
}
public Typeface getTypeface(String file) {
Typeface result = map.get(file);
if (result == null) {
result = Typeface.createFromAsset(con.getAssets(), file);
map.put(file, result);
}
return result;
}
}
我通过调用类和字体
TypefaceCache typecache = new TypefaceCache(activity);
Typeface roboto = typecache.getTypeface("fonts/Roboto-Regular.ttf");
但结果是一样的......