Android Imge Picasso Square Cache Size

北战南征 提交于 2019-12-08 07:08:56

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!