毕加索可以为我排队吗? [英] Can Picasso queue for me?

查看:224
本文介绍了毕加索可以为我排队吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是关于毕加索行为的一个关键点我不知道。

Here's a critical point I don't know concerning the behavior of Picasso.

想象一下,你正在展示十件物品的幻灯片。比如说,它们在屏幕上都是10秒钟。

Imagine you are, say, showing a slide-show of ten items. Say, they are on-screen for ten seconds each.

理想的行为是这样的:在幻灯片放映开始时,我只是执行以下操作:

The ideal behavior would be this: at the start of the slide show, I simply perform following:

picasso.get( url1 )
picasso.get( url2 )
picasso.get( url3 )
picasso.get( url4 )
picasso.get( url5 )
picasso.get( url6 )
picasso.get( url7 )
picasso.get( url8 )
picasso.get( url9 )
picasso.get( url10 )

事实上毕加索会一次做一个,排队

And, in fact, Picasso would do those one at a time, in a queue.

毕加索的行为是什么,如果我告诉它预先一次温暖10个网址?

What is the behavior of Picasso, if I tell it to pre-warm 10 urls all at once?

Picasso是否可以一次只做一件事,按顺序 - 是否有这样的选择?

Is it possible to have Picasso do things only one at a time, in order - is there such an option?

(产生的其他问题是,你可以取消队列,还是......?)

(Other questions arising are, can you cancel the queue, or ...?)

感谢一个惊人的答案@alicanozkara在这个页面上我第一次了解了

thanks to an amazing answer @alicanozkara on this page I learned for the first time about

https://github.com/facebook/fresco

(13k星)无论好坏,我认为毕加索时代可能已经过去了。

(13k stars) for better or worse I think the Picasso era is probably over.

推荐答案

仅使用 Picasso ,我认为你可以实现的目标是:

Using only Picasso, what I think you can achieve is:

1)使用 fetch()在缓存中加载所有图像异步,如下所示:

1) Load all the images asynchronously in the cache using fetch() like so:

Picasso.with(context).load(URL).fetch();

您还可以为想要提前加载的图片添加优先级:(可能会提到前几个的高优先级)幻灯片的图片)

You can also add priority for images you want to load early: (Maybe mention high priority for first few images of the slide)

Picasso.with(context)
.load(URL)
.priority(Picasso.Priority.HIGH) // Default priority is medium
.fetch();

2)关于取消队列,您可以添加一个公共 tag()到你的图片,你可以随时暂停/取消/恢复!

2) About cancelling the queue, you can add a common tag() to your images and you can pause/cancel/resume anytime!

private static final Object TAG_OBJECT = Object();

Picasso.with(context)
.load(URL)
.tag(TAG_OBJECT) 
// can be any Java object, must be the same object for all requests you want to control together.

然后我们可以这样控制标签:

Then we can control the tag like so:

Picasso.with(context)
.pauseTag(TAG_OBJECT)
//.resumeTag(TAG_OBJECT)
//.cancelTag(TAG_OBJECT)

3)我想建议的另一件重要事情是当你预售 - 加载图像,只将它们保存到磁盘缓存中,并在显示时将它们加载到内存缓存中。它将防止从内存缓存中刷新其他重要图像:

3) Another important thing I would like to suggest is when you are pre-loading your images, only save them into your disk-cache, and load them to your memory-cache only while displaying. It will prevent flushing other important images from the memory-cache:

Picasso  
.with(context)
.load(URL)
.memoryPolicy(MemoryPolicy.NO_STORE) //Skips storing the final result into memory cache.
.fetch()

4)为了顺序加载你的队列中的图像,您可以使用传递您自己的 ExecutorService SingleThreadExecutor )执行者(ExecutorService)方法,出现在 Picasso.Builder

4) For sequentially loading your images in a queue, you can pass your own ExecutorService (SingleThreadExecutor in your case) using executor(ExecutorService) method, present in Picasso.Builder

你甚至可以改变使用 downloader(Downloader)方法和使用 memoryCache(Cache)方法的内存缓存的磁盘缓存大小在 Picasso.Builder 类中找到。

You can even change the size of disk cache by using downloader(Downloader) method and your memory cache using memoryCache(Cache) method, both found in Picasso.Builder class.

其他令人敬畏的图书馆:

Glide

Fresco

这篇关于毕加索可以为我排队吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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