Image-Universal-Loader的使用
//1:创建自己的Application,然后继承Application
public class App extends Application {
//2:注册 Application
@Override
public void onCreate() {
super.onCreate();
//3:设置框架的一些属性,然后初始化 ImageLoader
DisplayImageOptions options = new DisplayImageOptions.Builder()
// 正在加载时显示的占位图
.showImageOnLoading(R.mipmap.zhan)
// // URL为空时显示的占位图
// .showImageForEmptyUri(R.mipmap.zhaobudao)
// 加载失败时显示的占位图
.showImageOnFail(R.mipmap.shibai)
// //可在实现中对 bitmap 做一些额外处理,比如加圆角、动画效果。
// .displayer(new SimpleBitmapDisplayer())
// bitmap的质量,默认为ARGB_8888
.bitmapConfig(Bitmap.Config.ARGB_8888)
.build();
//1构建
ImageLoaderConfiguration loaderConfiguration = new ImageLoaderConfiguration.Builder(this)
//把我们写的设置添加到构建中
.defaultDisplayImageOptions(options)
//构建
.build();
//获得实例
ImageLoader imageLoader = ImageLoader.getInstance();
//初始化
imageLoader.init(loaderConfiguration);
//初始化完成后进入适配器加载图片
}
}
======================
//请求图片需要在Application中注册
///在你自己的项目中 build.gradle( : 你项目的名字)
// implementation 'com.nostra13.universalimageloader:universal-image-loader:1.9.5'
//然后新建一个App的类
String uri = datas.getPic_url();
///4:请求图片(参数:1.图片接口 ,2 imageview的控件)
ImageLoader.getInstance().displayImage(uri, imageView);
//完成
//注意 网络权限| |