直播平台制作,Glide加载网络图,进度条显示

发布时间 2023-10-23 14:14:31作者: 云豹科技-苏凌霄

直播平台制作,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;

 

 以上就是 直播平台制作,Glide加载网络图,进度条显示,更多内容欢迎关注之后的文章