开发者

android load drawables into cache

I have an activity which is playing a beat and alternating drawables from my drawables folder in tandem. Unfortunately the loading of the drawables is too s开发者_Python百科low and it goes out of sync.

Does anyone have a proposed solution?


I think it's common to load all your bitmaps ahead of time (perhaps with BitmapFactory.decodeResources()). Once loaded, just hang on to those references for your drawing.

Does that answer your question?


The answer is in the question. You can create a class that acts like a bitmap cache that uses a backing HashMap to save references to the decoded bitmaps. The simplest thing to do is to cache the full size bitmap and just key it with the generated int id from R.java. I did something similar, but I included the resizing logic and keyed it by a string in the form resourceid:width:height. You can provide a remove method and a clear method if you want to make sure you keep your memory down, but remember to recycle your bitmaps for older versions of the OS.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜