j2e*_*nue 3 image progressive-download image-loading android-recyclerview
我正在寻找一种我可以使用的设计模式,以便在android recyclerView中我可以快速加载低质量的图像,然后调用高质量的图像,之后将覆盖低质量的图像。我经常看到先加载低质量图像,然后加载高质量图像的情况。
但是如何在适配器中实现回收者视图。现在我正在使用毕加索进行缓存和图像加载。因此,例如,这里是指向低质量图像的链接:
http://example.com/lowQuality.jpg以及高质量的http://example.com/highQuality.jpg
所以在我的recyclerView适配器中,如果我在viewholder中这样做:
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 ?
}
}
Run Code Online (Sandbox Code Playgroud)
因此,要明确一点,只要高质量图像尚未加载,我希望低质量图像可以首先显示。
更新:我真正想要的是我在低质量图像快速加载的应用程序上看到的效果,然后在几秒钟后过渡到更高质量。如果还有其他工具或方法可以让我知道。我想要与whatsapp个人资料图片相同的效果(它如何从劣质逐渐淡化为高质量)。
我找到了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 );
}
Run Code Online (Sandbox Code Playgroud)
在更多信息源在这里