问题
I have an application contains a range of image appears by links using glide library, my app takes a long time to load all images so is it possible to load image by image ( one by one ).
Glide.with(context)
.load(imageId.get(position))
.diskCacheStrategy(DiskCacheStrategy.ALL)
.priority(Priority.HIGH)
.listener(new RequestListener<String, GlideDrawable>() {
@Override
public boolean onException(Exception e, String model, Target<GlideDrawable> target, boolean isFirstResource) {
return false;
}
@Override
public boolean onResourceReady(GlideDrawable resource, String model, Target<GlideDrawable> target, boolean isFromMemoryCache, boolean isFirstResource) {
progressBar.setVisibility(View.GONE);
return false;
}
})
.into(holder.CategoryImage);
回答1:
Try this
Glide.with(context)
.load(imageId.get(position))
.diskCacheStrategy(DiskCacheStrategy.ALL)
.priority(Priority.HIGH)
.listener(new RequestListener<String, GlideDrawable>() {
@Override
public boolean onException(Exception e, String model, Target<GlideDrawable> target, boolean isFirstResource) {
return false;
}
@Override
public boolean onResourceReady(GlideDrawable resource, String model, Target<GlideDrawable> target, boolean isFromMemoryCache, boolean isFirstResource) {
progressBar.setVisibility(View.GONE);
return false;
}
})
.thumbnail(0.1f) // this will do the trick
.into(holder.CategoryImage);
if it does not work, Try this way,
Glide.with(context)
.load(imageId.get(position))
.diskCacheStrategy(DiskCacheStrategy.ALL)
.priority(Priority.HIGH)
.override(100,100)
.listener(new RequestListener<String, GlideDrawable>() {
@Override
public boolean onException(Exception e, String model, Target<GlideDrawable> target, boolean isFirstResource) {
return false;
}
@Override
public boolean onResourceReady(GlideDrawable resource, String model, Target<GlideDrawable> target, boolean isFromMemoryCache, boolean isFirstResource) {
progressBar.setVisibility(View.GONE);
Glide.with(context).load(imageId.get(position))
.diskCacheStrategy(DiskCacheStrategy.ALL)
.priority(Priority.HIGH)
.into(holder.CategoryImage);
return false;
}
})
.into(holder.CategoryImage);
回答2:
Use this code :
Glide.with(this)
.load(sharePref.getUserImage())
.asBitmap()
//.centerCrop()
.placeholder(R.drawable.ic_account_circle_black_48dp) // .placeholder(R.drawable.user)
.into(new BitmapImageViewTarget(user_Image) {
@Override
protected void setResource(Bitmap resource) {
RoundedBitmapDrawable circularBitmapDrawable =
RoundedBitmapDrawableFactory.create(getResources(), resource);
circularBitmapDrawable.setCircular(true);
user_Image.setImageDrawable(circularBitmapDrawable);
}
});
来源:https://stackoverflow.com/questions/45937898/how-to-load-image-by-image-using-glide-library