在Recyclerview中下载图像 [英] Downloading Image in Recyclerview
问题描述
我有一个回收站视图,其中Viewholder
中有一个Imageview
.
图像是通过适配器onBindViewHolder
中的AsyncTask
下载的.
I have a recycler view which has an Imageview
in the Viewholder
.
The Image is downloaded via AsyncTask
in the onBindViewHolder
in the adapter.
问题是当我向下或向上滚动时,会调用onBindViewHolder
来回收视图支架,并且图像会一次又一次地下载.
现在,我了解到Recyclerview
应该是这样工作的.
因此,有人可以告诉我是否可以采取其他措施避免多次下载图片?
还是回到ListView
更好?
The problem is when I scroll down or up, the onBindViewHolder
is called for recycling the view holder and the Images are downloaded again and again.
Now I understand that this is how Recyclerview
is supposed to work.
So can anyone tell me if anything can be done to avoid downloading the Images more than once?
Or will it be better to move back to ListView
?
推荐答案
使用毕加索并缓存图像.而且我猜默认是Picasso缓存图像.
Use Picasso and cache the image. And I guess Picasso Cache the image by default.
示例
Picasso.with(context).load("http://i.imgur.com/DvpvklR.png").into(imageView);
这篇关于在Recyclerview中下载图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!