【发布时间】:2014-09-09 13:48:31
【问题描述】:
我有点困惑:通常,当将图像异步加载到某种列表视图(无论是在 Android 或 iOS 上还是在另一个平台上抽象地)时,您基本上必须这样做..
-- 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.
这是延迟加载异步图像的基础。例如,Lucas Rocha 在这里的一篇著名文章中完美地解释了这一点:
http://lucasr.org/2012/04/05/performance-tips-for-androids-listview/
(向下滚动到确切的“这只是您可以做到的一种方法的简单草图:” ...)
现在好了,据我了解实际上,毕加索完全自动地为您做到了这一点。
毕加索自己“知道”视图是否发生了变化。如果视图发生了变化,毕加索知道不必费心加载它
我完全正确吗?这是毕加索的内置功能,我不需要做任何其他事情吗?
(除此之外 - 我有点困惑“毕加索是如何做到这一点的;瞥一眼它,我看不到毕加索的任何魔术代码,它记录了 id 或持有者的某些东西?视图?有问题.)
为了清楚起见,我以通常的方式使用 Picasso,基本上是在 getView 的末尾...
Picasso.
with(State.mainContext).
load(imageFile.getUrl()).
placeholder(R.drawable.default).
noFade().
into(v.hexaIV);
【问题讨论】:
-
假设您正在使用
Picasso.with(context).load("http://i.imgur.com/DvpvklR.png").into(imageView);从适配器的 getView 加载图像...加载到尚未完成但取消上一个下载的同一 imageView(在视图被重用后)... Piccaso对象有 2 个地图来存储 ImageView(或其他目标)上发生的操作 ... targetToAction 和 targetToDeferredRequestCreator
标签: android lazy-loading picasso async-loading