Android的毕加索配置LruCache尺寸 [英] Android Picasso Configure LruCache Size

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

问题描述

我现在用的是毕加索的趋势在我的项目,但我已经倾倒堆和它看起来像这样。现在,昨天它给了我48M的 LruCache 毕加索使用。

I am using the trending Picasso in my Project, but I have dumped the heap and it looks like this. Now yesterday it gives me 48M for LruCache used in Picasso.

我怎么可以指定它的大小?

How could I specify the size of it?

注:我的加载的图像显然是大

Note: my loaded images are apparently large.

如果有人想出了飞度() centerCrop(),我读过的那些功能降低图像大小,对不对?但有时我也显示在众目睽睽之下的ListView 小图片。

If someone came up with fit() or centerCrop(), I've read that those functions reduce image size, right? But sometimes I have to display small images in the ListView in full view.

现在,做这些功能缓存缩小图像?

Now, do those functions cache a scaled down image?

推荐答案

在默认情况下,毕加索利用可用堆为它的LRU的1/7。这是一个幸福的比例在所有设备上不够好,效果最好。

By default, Picasso uses 1/7th of the available heap for it's LRU. This is a "happy" fraction that works best on all devices well enough.

您可以通过传递一个自定义实例 Picasso.Builder 配置内存高速缓存的大小。它可以是一个实例 LruCache 这需要一个最大尺寸或缓存的任何其他实例

You can configure the size of the memory cache by passing a custom instance to Picasso.Builder. It can be an instance of the LruCache which takes a max size or any other instance of Cache.

Picasso p = new Picasso.Builder(context)
    .memoryCache(new LruCache(24000))
    .build();

你去缩小这个缓存的大小之前,但是,请记住,保持在RAM 位图实例,使它们能够立即显示。未使用的RAM被浪费内存。内存缓存应使用尽可能多的RAM,且不会造成奥姆斯(显然)或不必要的GC以释放空间。

Before you go shrinking this cache size, however, remember that keeping Bitmap instances in RAM allows them to be instantly displayed. Unused RAM is wasted RAM. The memory cache should use as much RAM as possible without causing OOMs (obviously) or unnecessary GC to free space.

这篇关于Android的毕加索配置LruCache尺寸的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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