安卓Glide加载网络图,进度条显示

安卓 Glide 网络图 进度条

大家好,我是 感觉使用glide加载网络图有时候网速慢,没有个效果,于是乎 在网络搜了半天, 发现这个方法 不多啰嗦,如下代码吧:

1,首先在build.gradle添加依赖 compile ‘com.github.bumptech.glide:glide:3.7.0’
2,我就直接拷贝代码了:
//显示图片

Glide.with(getContext())
                    .load(content)
                   .into(new ImageViewTarget<GlideDrawable>(iv_pic) {
                       //               图片开始加载
                       @Override
                       public void onLoadStarted(@Nullable Drawable placeholder) {
                           super.onLoadStarted(placeholder);
                           Log.d("info", "图片开始加载");
                           dialog.show();
                       }
                       @Override
                       public void onLoadFailed(Exception e, Drawable errorDrawable) {
                           super.onLoadFailed(e, errorDrawable);
                           Log.d("info", "图片加载失败");
                           dialog.dismiss();
                       }
                       @Override
                       protected void setResource(GlideDrawable resource) {
                           Log.d("info", "图片设置资源");
                       }
                       @Override
                       public void onResourceReady(GlideDrawable resource, GlideAnimation<? super GlideDrawable> glideAnimation) {
                           super.onResourceReady(resource, glideAnimation);
                           dialog.dismiss();
                           iv_pic.setImageDrawable(resource);
                           Log.d("info", "图片加载完成");
                       }
                   });

3,然后我还要说的是我遇到的坑, 注意导入的包 不能出错,如下:

import android.graphics.drawable.Drawable;
import com.bumptech.glide.Glide;
import com.bumptech.glide.load.resource.drawable.GlideDrawable;
import com.bumptech.glide.request.animation.GlideAnimation;
import com.bumptech.glide.request.target.ImageViewTarget;
import javax.annotation.Nullable;

切记!!!

嗯 好了,就这样,哈哈哈 不对的地方也可以说出来


版权声明:本文为mawlAndroid原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。