它是绝对正确的毕加索理解不若视图已经被回收的加载? [英] Is it absolutely correct that Picasso understands NOT to load if the view has been recycled?

查看:332
本文介绍了它是绝对正确的毕加索理解不若视图已经被回收的加载?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有点困惑:作为一个规则,当异步加载图像某种列表视图(无论是在Android或iOS或在另一个平台上的抽象),你必须基本上做到这一点。

   - 请记的单元,这是(比方说,#213)
- 开始从网上获取的图像。
- 它已经从网装载。我们现在是什么电池?
- 如果我们是还是213,图像加载到图像视图!
- 如果我们不再是213,忘掉它。

这是懒加载图像异步基础。例如,卢卡斯罗沙完美地解释了它在一个著名的文章在这里:

http://lucasr.org/2012/04 / 05 /性能技巧换机器人,列表视图/

(向下滚动到正是这里只是你能做到这一点的一种方式简单化的草图:......)

现在好了,据我了解毕加索其实做到这一点对你来说,完全自动。

在其自己的,毕加索的知道如果视图改变了。如果认为已经改变,毕加索知道不要打扰加载它

我是完全正确的?这是毕加索的内置功能,我需要什么也不做?

(题外话 - 我有点困惑如何毕加索做到这一点;它一眼,我不能看到毕加索任何魔法code其中它使一个音符持有人的ID ??什么的?查看?有问题。)

在此先感谢...


仅有TBC我以通常的方式完全一样使用毕加索,基本上在getView ...

的端部

 毕加索。
  与(State.mainContext)。
  负荷(imageFile.getUrl())。
  占位符(R.drawable.default)。
  noFade()。
  成(v.hexaIV);


解决方案

毕加索是美丽的。您只需要该getView()方法中一行 Picasso.with(C).load(URL).into(IMG);

他们究竟是如何做到这一点,我不知道,但毕加索之前存在我做我自己的图像加载器,它不是那么困难。

比方说,你在你的图像加载器code有地图网址的和ImageView的地方。

所以,只要code通 IMG 来,它会针对这张图,如果是已经加载其他网址为同一 IMG 使用基本的Java mImg.equals(IMG),如果匹配,它知道,即使你仍然会缓存URL,它不应该交付可绘制到ImageView的。

有就是,你可能想直接取消负荷极少数情况下,在这些情况下,您可以拨打 Picasso.with(C).cancel(IMG); ,但是这是罕见的是必要的。

I'm a little confused: as a rule when async loading images to some sort of list view (whether on Android or iOS or in the abstract on another platform), you essentially must do this ..

-- make a note of "which" cell this is (say, #213)
-- start getting the image from the net.
-- it has loaded from the net. What cell are we now?
-- if we are "still" 213, load the image to the image view!
-- if we are "no longer" 213, just forget about it.

this is a basic in lazy-loading async images. For example, Lucas Rocha explains it perfectly in a famous article here:

http://lucasr.org/2012/04/05/performance-tips-for-androids-listview/

(scroll down to exactly "Here is just a simplistic sketch of one way you could do it:" ...)

Well now, as I understand it Picasso in fact does this for you, completely automatically.

On its own, Picasso 'knows' if the view has changed. If the view has changed, Picasso knows not to bother loading it

Am I completely correct? This is a built-in feature of Picasso, and I need do nothing else?

(Aside - I'm somewhat confused "how" Picasso does this; glancing at it I can't see any magic code in Picasso where it makes a note of the id?? or something of the holder? view? in question.)

Thanks in advance...


Just TBC I'm using Picasso in the usual way exactly like this, essentially at the end of getView...

Picasso.
  with(State.mainContext).
  load(imageFile.getUrl()).
  placeholder(R.drawable.default).
  noFade().
  into(v.hexaIV);

解决方案

yes, Picasso is that beautiful. You only need that one line inside the getView() method Picasso.with(c).load(url).into(img);

how they exactly do it, I'm not sure, but before Picasso existed I did my own image loader and it's not so difficult.

Let's say you have a map of Url and ImageView somewhere in your image loader code.

So whenever the code pass img to it, it checks against this map, if it is already loading other URL for the same img using basic Java mImg.equals(img), if it matches, it knows that, even thou still will cache that URL, it should not deliver the Drawable to the ImageView.

There're a few rare cases that you might want to directly cancel a load, on those cases you can call Picasso.with(c).cancel(img);, but that's rare to be necessary.

这篇关于它是绝对正确的毕加索理解不若视图已经被回收的加载?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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