RecyclerView 中动态调整imageview 大小,用Glide加载图片,滑动过程中图片内容变大

 问题: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);
    }
});

 

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值