我正在寻找一种可以使用的设计模式,以便在 android recyclerView 中我可以以低质量快速加载图像,然后还可以调用高质量图像将
之后重写低质量图像。我经常看到先加载低质量图像,然后再加载高质量图像。
但是,这是如何在回收器视图的适配器中完成的。现在我正在使用 picasso 进行缓存和图像加载。例如,这里是一个低质量图像的链接:
http://example.com/lowQuality.jpg http://example.com/lowQuality.jpg以及同样高品质http://example.com/highQuality.jpg http://example.com/highQuality.jpg
因此,如果我在视图持有者中执行此操作,则在我的 recyclerView 适配器中:
public class SearchItemHolder extends RecyclerView.ViewHolder {
@BindView(R.id.iv)
ImageView iv;
@BindView(R.id.tv_description)
TextView tv_description;
public SearchItemHolder(View view) {
super(view);
ButterKnife.bind(this, view);
}
public void bindSearch(final SearchModel searchModel) {
String description = searchModel.getProductName();
final String imageLowQualityIDUrl = searchModel.getIdLowQualityImage();
final String imageHighQualityIDUrl = searchModel.getIdHighQualityImage();
tv_price.setText(price);
tv_description.setText(description);
Picasso.with(mContext).load(imageLowQualityIDUrl).into(iv);
//but how to switch it to high quality URL after its finished loading ?
}
}
所以要明确的是,我希望只要尚未加载高质量图像,就可以先显示低质量图像。
更新:我真正想要的是我在低质量图像快速加载的应用程序上看到的效果,然后在几秒钟后转换为更高质量。如果有其他工具或方法可以做到这一点,请告诉我。我想要与 Whatsapp 个人资料图像相同的效果(它如何从低质量淡入高质量)。
我找到了解决方案Glide https://github.com/bumptech/glide。
您可以指定要加载为缩略图的低分辨率图像。所有你需要的是:
private void loadImageThumbnailRequest() {
// setup Glide request without the into() method
DrawableRequestBuilder<String> thumbnailRequest = Glide
.with( context )
.load( yourData.getLowQualityLink() );
// pass the request as a a parameter to the thumbnail request
Glide
.with( context )
.load( yourData.getHdUrl() )
.thumbnail( thumbnailRequest )
.into( imageView );
}
更多信息在source https://futurestud.io/tutorials/glide-thumbnails here
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)