My application that uses an ice cream sandwich for Android, after importing roboto.ttf and roboto-bold.ttf fonts into the font folder and after installing four text images with these fonts, scrolls the list very VERY slowly. Does anyone know a way to optimize performances? Are there any tips and tricks to increase speed?
I make it clear that this was very smooth before inserting these lines of code:
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);
I am adding a class that can help with font caching:
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; } }
I call the class and font through
TypefaceCache typecache = new TypefaceCache(activity); Typeface roboto = typecache.getTypeface("fonts/Roboto-Regular.ttf");
but the result is the same ...
source share