图片加载框架ImageLoader

  •  1.在manifest中注册android:name=".MyApplication"
  •  2.创建一个类extends Application
  •  3.ImageLoaderConfiguration是图片加载器ImageLoader的配置参数,使用了建造者模式new ImageLoaderConfiguration.Builder(this).build(); //构建完成
  •  其自带参数有:new ImageLoaderConfiguration.Builder(this)
  •  .threadPoolSize(3) //设置开启线程池数
  •  .memoryCacheSize(10*1024) //设置内存的缓存大小
  •  .diskCacheSize(20*1024)//设置sd卡缓存区大小
  •  .writeDebugLogs() //打印log信息---打印出图片的url以及图片的最大宽度和高度
  •  .build(); //构建完成
  •  //得到ImageLoader对像
    ImageLoader imageLoader = ImageLoader.getInstance();
  •  //进行初使化
    imageLoader.init(configuration);

/**
         * 第一个参数,是图片的url
         * 第二个参数是imageView控件
         */
       // ImageLoader.getInstance().displayImage(imgesUrl[position],iv);

        DisplayImageOptions options = new DisplayImageOptions.Builder()
                .showImageOnLoading(R.mipmap.ic_launcher)   //在图片没有加载进来之前显示的图片
                .showImageForEmptyUri(R.mipmap.ap)   //如果图片的地址为空的话,就让其加载设定好的图片
                .showImageOnFail(R.drawable.bf)    //加载失败显示的图片
                .cacheInMemory(true)    //设置下载的图片缓存到内存中
                .cacheOnDisk(true)      //设置下载的图片是否缓存到sd卡中
                .build();

        ImageLoader.getInstance().displayImage(imgesUrl[position],iv,options);

原文地址:https://www.cnblogs.com/Nigeria/p/8007021.html