imageloader异步加载图片;

package com.baway.applicationn;

import android.app.Application;

import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.ImageLoaderConfiguration;
import com.nostra13.universalimageloader.core.display.RoundedBitmapDisplayer;


public class Myapplication extends Application{

public void onCreate() {
// TODO Auto-generated method stub
super.onCreate();
Log.i("TAG", "自定义的application类调用了.....");
//创建ImageLoader的默认配置
// ImageLoaderConfiguration confing = ImageLoaderConfiguration.createDefault(this);
//得到sdcard路径
String sdpath = Environment.getExternalStorageDirectory().getPath();
//自定义ImageLoaderConfiguration
ImageLoaderConfiguration confing = new ImageLoaderConfiguration.Builder(this)
.memoryCacheExtraOptions(480, 800)// default = device screen dimensions 内存缓存文件的最大长宽
.diskCacheExtraOptions(480, 800, null)// 本地缓存的详细信息(缓存的最大长宽),最好不要设置这个
// .taskExecutor(null)
// .taskExecutorForCachedImages(null)
.threadPoolSize(3)// default 线程池内加载的数量
.threadPriority(Thread.NORM_PRIORITY-2) // default 设置当前线程的优先级
.tasksProcessingOrder(QueueProcessingType.FIFO)//任务的处理顺序
.denyCacheImageMultipleSizesInMemory()
.memoryCache(new LruMemoryCache(2 * 1024 * 1024))////设置自己的内存缓存大小 2m
.memoryCacheSize(2 * 1024 * 1024)
// .memoryCacheSizePercentage(13)
.diskCache(new UnlimitedDiscCache(new File(sdpath+"/app1407a/imgcache")))//设置缓存的图片在sdcard中的存放位置
.diskCacheSize(50 * 1024 * 1024)
.diskCacheFileCount(100)
.diskCacheFileNameGenerator(new Md5FileNameGenerator())//md5加密的方式,或new HashCodeFileNameGenerator()
.imageDownloader(new BaseImageDownloader(this))
// .imageDecoder(new BaseImageDecoder(true))
.defaultDisplayImageOptions(null)//不适用默认的图片加载配置,使用自定义的
.writeDebugLogs()
.build();
//初始化
ImageLoader.getInstance().init(confing);
}

public static DisplayImageOptions getOptions(){
//自定义加载图片的配置信息
DisplayImageOptions option = new DisplayImageOptions.Builder()
.showImageOnLoading(R.drawable.ic_launcher)// 设置图片下载期间显示的图片
.showImageForEmptyUri(R.drawable.ic_launcher) // 设置图片Uri为空或是错误的时候显示的图片
.showImageOnFail(R.drawable.ic_launcher)// 设置图片加载或解码过程中发生错误显示的图片
.resetViewBeforeLoading(false)// default 设置图片在加载前是否重置、复位
// .delayBeforeLoading(1000)// 下载前的延迟时间
.cacheInMemory(true)// default 设置下载的图片是否缓存在内存中
.cacheOnDisk(true)// default 设置下载的图片是否缓存在SD卡中
.considerExifParams(false)
.imageScaleType(ImageScaleType.IN_SAMPLE_POWER_OF_2)//设置图片的显示比例
.bitmapConfig(Bitmap.Config.RGB_565)// default 设置图片的解码类型
.displayer(new RoundedBitmapDisplayer(75))//设置图片的圆角半径
//.displayer(new FadeInBitmapDisplayer(100))//设置图片显示的透明度过程时间
.build();

return option;
}

}

 

在适配器调用imageloader时,括号里是三个参数;

ImageLoader.getInstance().displayImage(list.get(position).getGoods_img(), holder.imageView,Myapplication.getOptions());

posted @ 2016-04-05 16:03  zyy明天你好  阅读(249)  评论(0编辑  收藏  举报