B4J Question Loading Font Lag

tufanv

Expert
Licensed User
Longtime User
Hello,

With the start of the app I need to add around 300 label to a scrollview which all have to load a custom font. I use:

B4X:
for i=0 to 300
price(i).Font=fx.LoadFont(File.DirAssets,"twnb.ttf",14)
next

this makes a lag around 5 seconds on startup. What is the best way to load font for multiple files on startup. ( I need them on startup as I load the values of them from the server on startup )

Thanks
 

Lahksman

Active Member
Licensed User
Longtime User
I don't know if it would make much differrence but you could try:
B4X:
Dim f As Font
f = fx.LoadFont(File.DirAssets,"twnb.ttf",14)
For i=0 To 300
    price(i).Font=f
Next

EDIT: as usual Erel was faster :)
 
Upvote 0

tufanv

Expert
Licensed User
Longtime User
Why are you loading the same font file more than once?

It is never needed. Store it in a global variable and use it whenever you need.
yes , why am i doing that ? I don't know. Thanks for your answers.
 
Upvote 0
Top