使用 Glide 库设置完成图像加载后进度条的可见性 [英] Set visibility of progress bar gone on completion of image loading using Glide library
问题描述
我想要一个图像进度条,它会在图像加载时显示,但当图像加载完成时,我想将其设置为消失.早些时候我为此使用了毕加索库.但我不知道如何将它与 Glide 库一起使用.我知道那里有一些资源就绪功能,但我不知道如何使用它.谁能帮我?
Hi I want to have a progress bar for image which will shown while image loading but when image loading will be completed I want to set it to gone. Earlier I was using Picasso library for this. But I don't know how to use it with Glide library. I have idea that some resource ready function is there but I don't know how to use it. Can anyone help me?
毕加索图书馆代码
Picasso.with(mcontext).load(imgLinkArray.get(position).mUrlLink)
.into(imageView, new Callback() {
@Override
public void onSuccess() {
progressBar.setVisibility(View.GONE);
}
@Override
public void onError() {
}
})
;
现在我如何用 Glide 做到这一点?
Now How Can I do this with Glide?
Glide.with(mcontext).load(imgLinkArray.get(position).mUrlLink)
.into(imageView);
我可以通过 Glide 加载图像,但是如果加载图像,我如何在代码中的某处编写 progressBar.setVisibility(View.GONE);
?
I am able to load image by this with Glide but how can I write progressBar.setVisibility(View.GONE);
somewhere in code if image get loaded?
推荐答案
问题比较老了,不知道那个时候glide是什么情况,现在用listener就可以轻松搞定(不像在选择为正确的答案中提出).
Question is rather old, and I don't know what was the situation with glide in those times, but now it can be easily done with listener (not as proposed in the answer chosen as correct).
progressBar.setVisibility(View.VISIBLE);
Glide.with(getActivity())
.load(args.getString(IMAGE_TO_SHOW))
.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(imageFrame)
;
如果你想自己处理动画之类的事情,你会返回 true,如果你想滑翔来为你处理它们,你会返回 false.
You return true if want to handle things like animations yourself and false if want glide to handle them for you.
这篇关于使用 Glide 库设置完成图像加载后进度条的可见性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!