圆角问题弄了好久,大部分人说这样解决
重写图片的宽高,然后bitmapTransform 里面 传fitcenter 就好了,
有的说recyclerview 里面要设置一下,设置什么没查到,反正就是没用。
后面自己找了Glide 设置圆角的方法
Glide.with(mContext).load(imageURL).asBitmap().diskCacheStrategy(DiskCacheStrategy.NONE)
.into(new SimpleTarget<Bitmap>() {
@Override
public void onResourceReady(Bitmap resource, GlideAnimation<? super Bitmap> glideAnimation) {
RoundedBitmapDrawable circularBitmapDrawable =
RoundedBitmapDrawableFactory.create(mContext.getResources(), resource);
circularBitmapDrawable.setCornerRadius(DensityUtils.dp2px(mContext, 15));
pic.setImageDrawable(circularBitmapDrawable);
}
@Override
public void onLoadFailed(Exception e, Drawable errorDrawable) {
super.onLoadFailed(e, errorDrawable);
pic.setImageDrawable(mContext.getResources().getDrawable(R.drawable.default_news));
}
});
//glide 4.7版本的,先按照重写的大小裁剪之后再构建圆角
Glide.with(mContext).asBitmap().load(imageURL).apply(new RequestOptions().centerCrop().diskCacheStrategy(DiskCacheStrategy.NONE).override(DensityUtils.dp2px(getContext(),41),DensityUtils.dp2px(getContext(),41))).into(new SimpleTarget<Bitmap>() {
@Override
public void onResourceReady(@NonNull Bitmap resource, @Nullable Transition<? super Bitmap> transition) {
RoundedBitmapDrawable circularBitmapDrawable =
RoundedBitmapDrawableFactory.create(mContext.getResources(), resource);
circularBitmapDrawable.setCornerRadius(DensityUtils.dp2px(mContext, 5));
imageView.setImageDrawable(circularBitmapDrawable);
}
});
网传asBitmap()之后placeholder ,error 会无效,试了一下果然如此,于是才重写了其他方法,满足我的需求了,另外圆角大小不一致的问题也不见了。感觉网上好多无用的代码,浪费时间看。