My application scrolls very badly after importing the roboto font into the Properties / Fonts folder

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 ...

+4
source share
3 answers

this is my solution: in asynctask in which I run ui i, insert a class variable

 private final HashMap<String, Typeface> map; 

and then I initialize it through the class constructor

 map = new HashMap<String, Typeface>(); 

i implements a method that loads my font into a class:

 private Typeface getTypeface(String file, Context context) { Typeface result = map.get(file); if (result == null) { result = Typeface.createFromAsset(context.getAssets(), file); map.put(file, result); } return result; } 

then whenever I want in asynctask, I add my favorite font i, loaded into the text fields, and all this is very smooth. Thank you all

0
source

You can try to cache your Typeface .

 public class TypefaceCache { private final HashMap<String, Typeface> map = new HashMap<String, Typeface>(); private Typeface getTypeface(String file, Context context) { Typeface result = map.get(file); if (result == null) { result = Typeface.createFromAsset(context.getAssets(), file); map.put(file, result); } return result; } } 
+4
source

I had this problem recently, the solution was to set the class to static, as described in this blog ;

 public class TypefaceSingleton { private static TypefaceSingleton instance = new TypefaceSingleton(); private TypefaceSingleton() {} public static TypefaceSingleton getInstance() { return instance; } public Typeface getTypeface() { return Typeface.createFromAsset(ThinkNearApp.getContext().getResources().getAssets(), "fonts/Roboto-Bold.ttf"); } } 
+1
source

All Articles