Android的IMGE毕加索广场缓存大小 [英] Android Imge Picasso Square Cache Size

查看:142
本文介绍了Android的IMGE毕加索广场缓存大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用im毕加索广场图书馆在我的Andr​​oid应用程序加载图像。这样做时,它也能正常工作是这样的:

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);

我的问题是图像的加载太慢,我想缓存要大于它是现在。我看到只有一个图像时缓存正常工作;第一次图像也不会被缓存,每一样code被称为时间之后,图像就会从缓存,而不是网络获取。
作为图像的数量增加,似乎缓存太小和图像被替换。可高速缓存的大小进行修改/放大?

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?

任何帮助,这将大大AP preciated。

Any help with this will be greatly appreciated.

感谢

推荐答案

您可以指定自己的LRUCache毕加索使用。

You can specify your own LRUCache for Picasso to use.

 Picasso picasso = new Picasso.Builder(context).memoryCache(
            new LruCache(cacheSize)).build();

我想在默认情况下,毕加索利用可用堆为它的LRU的1/7。但是你可以通过使用设备的内存类计算出你想要的大小。

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;

祝您好运!

这篇关于Android的IMGE毕加索广场缓存大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆