challenge(六)图片异步加载类库(Android-Universal-Image-Loader)的使用

参考:http://blog.csdn.net/vipzjyno1/article/details/23206387

一、GITHUB下载文件

路径:https://github.com/nostra13/Android-Universal-Image-Loader

把三个jar包放在工程目录下


二、AndroidManifest.xml设置

2.1 权限

<uses-permission android:name="android.permission.INTERNET" />  
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />  

2.2 application

<application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme"
        android:name="com.hy.challenge.applaction.ChallengeApplication"
        >


三、java实现

3.1 application初始化相关

public class ChallengeApplication extends Application{
	private Context context;

	@Override
	public void onCreate() {
		super.onCreate();
		
		context = getApplicationContext();
		
		initImageLoder();
	}
	
	/**
	 * 初始化ImageLoder库
	 */
	private void initImageLoder(){
		// 缓存路径
	    File cacheDir = StorageUtils.getOwnCacheDirectory(context, "imageloader/Cache");  
	    
		ImageLoaderConfiguration config = new ImageLoaderConfiguration
			.Builder(getApplicationContext())
//			.memoryCacheExtraOptions(480, 800) // 不用设置,尺寸在布局中定义
			.threadPoolSize(3)
			.threadPriority(Thread.NORM_PRIORITY - 2)
			.denyCacheImageMultipleSizesInMemory()
			.memoryCache(new UsingFreqLimitedMemoryCache(2 * 1024 * 1024))
			.memoryCacheSize(2 * 1024 * 1024)
			.discCacheSize(50 * 1024 * 1024)
			.discCacheFileNameGenerator(new Md5FileNameGenerator())
			.tasksProcessingOrder(QueueProcessingType.LIFO)
			.discCacheFileCount(100)
			.discCache(new UnlimitedDiskCache(cacheDir))
			.defaultDisplayImageOptions(DisplayImageOptions.createSimple())
			.imageDownloader(new BaseImageDownloader(context, 5 * 1000, 30 * 1000))
			.writeDebugLogs()
			.build();
		
		// 调用初始化
		ImageLoader.getInstance().init(config);
	}
}

3.2 使用

3.2.1 获取实例

ImageLoader imageLoader = ImageLoader.getInstance();
3.2.2 使用方式一

imageLoader.loadImage(imageUrl, options, new SimpleImageLoadingListener(){
	@Override
	public void onLoadingComplete(String imageUri, View view,
			Bitmap loadedImage) {
		imageView.setImageBitmap(loadedImage);
		super.onLoadingComplete(imageUri, view, loadedImage);
	}});
3.2.3 使用方式二(建议)
imageLoader.displayImage(imageUrl, imageView);

四、效果



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值