这是我的代码
Glide.with(context)
.load(url)
.asBitmap()
.placeholder(resourceId);
.centerCrop()
.into(new BitmapImageViewTarget(imageView) {
@Override
protected void setResource(Bitmap resource) {
RoundedBitmapDrawable circularBitmapDrawable =
RoundedBitmapDrawableFactory.create(imageView.getResources(),
resource);
circularBitmapDrawable.setCircular(true);
imageView.setImageDrawable(circularBitmapDrawable);
}
});
每当我调用此函数加载用户头像时,placeHolder被删除,我的ImageView显示为空背景视图,而url加载并下载图像放在ImageView上。
答案 0 :(得分:1)
尝试覆盖onLoadStarted方法,并在其中设置占位符图像。
Glide.with(context)
.load(url)
.diskCacheStrategy(DiskCacheStrategy.SOURCE)
.into(new GlideDrawableImageViewTarget(imageView) {
@Override
public void onResourceReady(GlideDrawable drawable, GlideAnimation anim) {
super.onResourceReady(drawable, anim);
}
@Override
public void onLoadFailed(Exception e, Drawable errorDrawable) {
super.onLoadFailed(e, errorDrawable);
imageView.setImageResource(R.drawable.avatar);
}
@Override
public void onLoadStarted(Drawable placeholder) {
super.onLoadStarted(placeholder);
imageView.setImageResource(R.drawable.avatar);
}
});
答案 1 :(得分:0)
给loadId加载...
Glide
.with(context)
.load(resourceId)
.placeholder(resourceId)
.fitCenter()
.into(new BitmapImageViewTarget(imageView) {
@Override
protected void setResource(Bitmap resource) {
RoundedBitmapDrawable circularBitmapDrawable =
RoundedBitmapDrawableFactory.create(imageView.getResources(),
resource);
circularBitmapDrawable.setCircular(true);
imageView.setImageDrawable(circularBitmapDrawable);
}
});