问题:因为要裁剪图片的所以使用了bitmap,但是使用之后占位图不显示了
原因:options的placeholder最终是不是要设置给imageview,但是你这里又没传给他imageview,你传的是SimpleTarget,那么他上哪找imageview帮你自动设置placeholder
解决方法1:本人亲测可行
在xml中直接设置src就行
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginRight="2dp"
android:scaleType="centerCrop"
android:src="@drawable/circle_icon_empty"
/>
options.skipMemoryCache(true).diskCacheStrategy(DiskCacheStrategy.ALL)
.bitmapTransform(new CenterCrop())
.placeholder(resHolderId)
.error(resErrId)
.dontAnimate();
Glide.with(imageView.getContext()).load(url).apply(options).into(new SimpleTarget<Drawable>() {
@Override
public void onResourceReady(@NonNull Drawable resource, @Nullable Transition<? super Drawable> transition) {
if (resource != null) {
BitmapDrawable bd = (BitmapDrawable) resource;
Bitmap bitmap = bd.getBitmap();
Bitmap endbitmap = BitmapCut.cutBitmap(bitmap); //调用裁剪图片工具类进行裁剪
if (bitmap != null)
imageView.setImageBitmap(endbitmap); //设置Bitmap到图片上
}
}
});
解决方式 2:没有测试,但是原理是可行
参考链接