Is it absolutely correct that Picasso understands NOT to load if the view has been recycled?

穿精又带淫゛_ 提交于 2019-12-08 05:10:11

问题


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


Just to be clear, 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);

回答1:


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.



来源:https://stackoverflow.com/questions/25746356/is-it-absolutely-correct-that-picasso-understands-not-to-load-if-the-view-has-be

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