为什么在Glide4 +中找不到GlideDrawableImageViewTarget
?有什么选择?
我的代码:
import com.bumptech.glide.request.target.GlideDrawableImageViewTarget;
Glide.with(getContext())
.load(R.drawable.loader_gif_image)
.diskCacheStrategy(DiskCacheStrategy.NONE)
.into(new GlideDrawableImageViewTarget(imageView));
}
答案 0 :(得分:6)
尝试
Glide.with(this)
.load(R.drawable.ic_favorite)
.apply(new RequestOptions().diskCacheStrategy(DiskCacheStrategy.NONE))
.into(new SimpleTarget<Drawable>() {
@Override
public void onResourceReady(@NonNull Drawable resource, @Nullable Transition<? super Drawable> transition) {
imageView.setImageDrawable(resource);
}
});
尝试
Glide.with(this)
.load(R.drawable.ic_favorite)
.apply(new RequestOptions().diskCacheStrategy(DiskCacheStrategy.NONE))
.into(new Target<Drawable>() {
@Override
public void onLoadStarted(@Nullable Drawable placeholder) {
}
@Override
public void onLoadFailed(@Nullable Drawable errorDrawable) {
}
@Override
public void onResourceReady(@NonNull Drawable resource, @Nullable Transition<? super Drawable> transition) {
imageView.setImageDrawable(resource);
}
@Override
public void onLoadCleared(@Nullable Drawable placeholder) {
}
@Override
public void getSize(@NonNull SizeReadyCallback cb) {
}
@Override
public void removeCallback(@NonNull SizeReadyCallback cb) {
}
@Override
public void setRequest(@Nullable Request request) {
}
@Nullable
@Override
public Request getRequest() {
return null;
}
@Override
public void onStart() {
}
@Override
public void onStop() {
}
@Override
public void onDestroy() {
}
});
答案 1 :(得分:4)
将dependency
中的build.gradle
更新为implementation 'com.github.bumptech.glide:glide:4.5.0'
尝试导入DrawableImageViewTarget
而不是GlideDrawableImageViewTarget
或使用以下代码。
Glide.with(context).load(R.drawable.common_google_signin_btn_icon_dark).apply(new RequestOptions().placeholder(R.drawable.common_google_signin_btn_icon_dark)).into(new DrawableImageViewTarget(holder.profileImage));
希望这会有所帮助
答案 2 :(得分:0)
new SimpleTarget<Bitmap>()
已过时。您可以使用
new SimpleTarget<Bitmap>()
。
@Override
public void onResourceReady(@NonNull Bitmap resource, @Nullable Transition<? super Bitmap> transition) {
}
@Override
public void onLoadCleared(@Nullable Drawable placeholder) {
super.onLoadFailed(placeholder);
}
@Override
public void onLoadFailed(@Nullable Drawable errorDrawable) {
super.onLoadFailed(errorDrawable);
}
};```
答案 3 :(得分:0)
GlideDrawable
已被弃用,使用简单的Drawable
Glide.with(mContext)
.load(item.getFriendUserPhotoUrl())
.listener(new RequestListener<Drawable>() {
@Override
public boolean onLoadFailed(@Nullable GlideException e, Object model, Target<Drawable> target, boolean isFirstResource) {
fullname.setVisibility(View.VISIBLE);
progressBar.setVisibility(View.GONE);
imageView.setImageResource(R.drawable.profile_default_photo);
return false;
}
@Override
public boolean onResourceReady(Drawable resource, Object model, Target<Drawable> target, DataSource dataSource, boolean isFirstResource) {
progressBar.setVisibility(View.GONE);
fullname.setVisibility(View.VISIBLE);
return false;
}
})
.into(holder.thumbnail);