问题
Im using Picasso square library to load images in my android application. This works fine when doing it like this:
Picasso.with(getApplicationContext()).load(Properties.IMAGE_URL + i).transform(transformation).centerCrop().fit().into(imgeButton);
My problem is that the loading of the image is too slow and I would like the cache to be bigger than it is right now. I see that when working with only one image the cache works properly; The first time the image will not be cached and right after that every time the same code is called, the image will be fetched from the cached and not the network. As the number of images increase, it seems that the cache is too small and images are replaced. Can the cache size be modified / enlarged?
Any help with this will be greatly appreciated.
Thanks
回答1:
You can specify your own LRUCache for Picasso to use.
Picasso picasso = new Picasso.Builder(context).memoryCache(
new LruCache(cacheSize)).build();
I think by default, Picasso uses 1/7th of the available heap for it's LRU. But you can calculate what size you want by using the devices memory class.
int memClass = ((ActivityManager) mApplicationContext
.getSystemService(Context.ACTIVITY_SERVICE))
.getLargeMemoryClass();
int cacheSize = 1024 * 1024 * memClass / 4;
Good Luck!
来源:https://stackoverflow.com/questions/26663767/android-imge-picasso-square-cache-size