问题:RecyclerView 中动态调整设置imageview 的LayoutParams
,用Glide加载圆角图片,滑动过程中图片内容变大且圆角消失
原方法:
Glide.with(MyApplication.getInstance())
.load(photoUrl)
.asBitmap()
.priority(priority)
.diskCacheStrategy(cache == true ? DiskCacheStrategy.ALL : DiskCacheStrategy.NONE)
.placeholder(DisplayUtil.getDrawable(imageView.getContext(),preLoadPhoto))
.error(DisplayUtil.getDrawable(imageView.getContext(),errorPhoto))
.centerCrop().into(new BitmapImageViewTarget(imageView) {
@Override
protected void setResource(Bitmap resource) {
RoundedBitmapDrawable circularBitmapDrawable = RoundedBitmapDrawableFactory.create(MyApplication.getInstance().getResources(), resource);
circularBitmapDrawable.setCornerRadius(dp);
holder.iv_img_cover.setImageDrawable(circularBitmapDrawable);
}
});
解决方法:
holder.iv_img_cover.post(new Runnable() {
@Override
public void run() {
//将上述方法放到此
}
});
经过上述方法解决了大部分手机的适配,但测试发现vivo手机无效,图片加载的方法改成
Glide.with(MyApplication.getInstance()) .load(photoUrl) .asBitmap() .priority(Priority.NORMAL) .diskCacheStrategy(DiskCacheStrategy.ALL) .placeholder(DisplayUtil.getDrawable(imageView.getContext(),R.drawable.shape_defual_pic)) .error(DisplayUtil.getDrawable(imageView.getContext(),R.drawable.shape_defual_pic)) .centerCrop().into(new SimpleTarget<Bitmap>() { @Override public void onResourceReady(Bitmap resource, GlideAnimation<? super Bitmap> glideAnimation) { RoundedBitmapDrawable circularBitmapDrawable = RoundedBitmapDrawableFactory.create(MyApplication.getInstance().getResources(), resource); circularBitmapDrawable.setCornerRadius(dp); imageView.setImageDrawable(circularBitmapDrawable); } });