ImageLoader加载图片
来源:互联网 发布:网络大电影演员演出费 编辑:程序博客网 时间:2024/06/07 13:13
一.导包universal-image-loader-1.9.5.jar
二.创建类继承Application,在清单文件注册
(记得写权限)
/**
*
* 这个是系统全局的Application, 它就是系统生命周期最长的上下文;
* 系统已启动,并不是直接进入MainActivity;二十先进入Application;
* 重写他的目的是,初始化系统全局的一些参数;比如imageLoader的全局配置;
* 生命周期和app的生命周期一样,
*
*/
public class App extends Application {
@Override
public void onCreate() {
super.onCreate();
ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(this)(必写)
.memoryCacheExtraOptions(480, 800) // max width, max height,即保存的每个缓存文件的最大长宽
.threadPoolSize(5)//线程池内加载的数量
.threadPriority(Thread.NORM_PRIORITY - 2)
.denyCacheImageMultipleSizesInMemory()
.memoryCache(new UsingFreqLimitedMemoryCache(2 * 1024 * 1024)) // You can pass your own memory cache implementation/你可以通过自己的内存缓存实现
.memoryCacheSize(2 * 1024 * 1024)
.tasksProcessingOrder(QueueProcessingType.LIFO)
.defaultDisplayImageOptions(DisplayImageOptions.createSimple())
.imageDownloader(new BaseImageDownloader(this, 5 * 1000, 30 * 1000)) // connectTimeout (5 s), readTimeout (30 s)超时时间
.writeDebugLogs() // Remove for release app
.build();//开始构建
//初始化imageloader;
ImageLoader.getInstance().init(config);(必写)
//初始化 代码统计;
}
}
public class MainActivity extends AppCompatActivity {
String[] images = {
"http://img.my.csdn.net/uploads/201407/26/1406383264_8243.jpg",
"http://img.my.csdn.net/uploads/201407/26/1406383248_3693.jpg",
"http://img.my.csdn.net/uploads/201407/26/1406383243_5120.jpg",
"http://img.my.csdn.net/uploads/201407/26/1406383242_3127.jpg",
"http://img.my.csdn.net/uploads/201407/26/1406383242_9576.jpg",
"http://img.my.csdn.net/uploads/201407/26/1406383242_1721.jpg",
"http://img.my.csdn.net/uploads/201407/26/1406383219_5806.jpg",
"http://img.my.csdn.net/uploads/201407/26/1406383214_7794.jpg",
"http://img.my.csdn.net/uploads/201407/26/1406383213_4418.jpg",
"http://img.my.csdn.net/uploads/201407/26/1406383213_3557.jpg",
"http://img.my.csdn.net/uploads/201407/26/1406383210_8779.jpg",
"http://img.my.csdn.net/uploads/201407/26/1406383172_4577.jpg",
"http://img.my.csdn.net/uploads/201407/26/1406383166_3407.jpg",
"http://img.my.csdn.net/uploads/201407/26/1406383166_2224.jpg"
};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ImageView imageView = (ImageView) findViewById(R.id.imageView);
//得到imageLoader的实例;
ImageLoader imageLoader = ImageLoader.getInstance();(必写)
DisplayImageOptions displayImageOptions = new DisplayImageOptions.Builder()
.showImageOnLoading(R.mipmap.ic_launcher) //设置图片在下载期间显示的图片
.showImageForEmptyUri(R.mipmap.ic_launcher)//设置图片Uri为空或是错误的时候显示的图片
.showImageOnFail(R.mipmap.ic_launcher) //设置图片加载/解码过程中错误时候显示的图片
.build();
imageLoader.displayImage(images[2], imageView);(必写)
}
}
- ImageLoader 加载本地图片
- ImageLoader加载圆形图片
- Android 图片加载ImageLoader
- imageloader加载网络图片
- ImageLoader加载图片配置
- imageloader加载本地图片
- ImageLoader加载圆形图片
- 图片的加载ImageLoader
- 图片加载类ImageLoader
- universal-ImageLoader加载图片
- Android图片加载ImageLoader
- ImageLoader加载圆形图片
- ImageLoader加载图片
- ImageLoader加载图片
- imageLoader加载本地图片
- 图片异步加载ImageLoader
- ImageLoader 加载图片错乱
- Android ImageLoader加载图片
- windows与Ubuntu双系统的安装
- openjudge 求逆序对数(线段树+离散化)
- Tomcat修改更换默认欢迎页面
- Ch_03 表、栈和队列
- Ti437x LED裸机程序全解
- ImageLoader加载图片
- 触摸[6] OverScroller
- 一个强悍而优美的Android视频播放器
- Android实现帧动画
- git将项目代码上传到github
- jsp的工作原理
- Action View
- 堆排序算法(java版)
- js中如何快速获取数组中的最大值最小值