您应该检查通用图像加载器。它有内存缓存、磁盘缓存,它异步加载你的图像,所以不会阻塞用户界面。您可以设置默认图像和/或无法获取图像等。它可以对图像进行采样以减少位图的内存占用。我真的建议您将其用于图像。
不要为您的案例禁用可回收,因为它没有意义。必须回收图像,因为如果未正确采样,它们的位图可绘制对象会产生非常高的内存过载。
RecyclerViewAdapter 中的示例用法:
@Override
public void onBindViewHolder(CustomViewHolder viewHolder, int position) {
String imageUri = "";//local or remote image uri address
//viewHolder.imgView: reference to your imageview
//before you call the displayImage you have to
//initialize imageloader in anywhere in your code for once.
//(Generally done in the Application class extender.)
ImageLoader.getInstance().displayImage(imageUri, viewHolder.imgView);
}
编辑:如今,我认为 Glide 作为我的主要图像加载和缓存库。你可以像这样使用它:
Glide.with(context)
.load(imageUri)
.placeholder(R.drawable.myplaceholder)
.into(imageView);