您的位置:首页 > 其它

图片的异步加载和双缓存学习笔记——ImageLoader

2013-05-06 00:54 295 查看

这个开源项目的使用需要下面三步:

一:初始化下载对象配置

    ImageLoaderConfiguration

二:初始化显示对象配置

    DisplayImageOptions   

三:ImageLoader

      此类用于在imageview中加载和显示bitmap,使用此类时必须首先调用init(ImageLoaderConfiguration),需要在第一时间初始化。

public class q4_BaseFragment extends Fragment {
/**
* 图片下载类
*/
protected ImageLoader mImagelLoader;
/**
* 图片下载配置
*/
protected ImageLoaderConfiguration configuration;

/**
* 图片显示配置
*/
protected DisplayImageOptions configuration_0;

@Override
public void onAttach(Activity activity) {
// TODO Auto-generated method stub
super.onAttach(activity);
initVar(activity);

}

/**
* 初始化变量
*/
private void initVar(Activity activity) {
configuration = new ImageLoaderConfiguration.Builder(activity)
.threadPriority(Thread.NORM_PRIORITY - 2)
.denyCacheImageMultipleSizesInMemory()
.discCacheExtraOptions(300, 300, CompressFormat.JPEG, 75, null)
.discCacheFileNameGenerator(new Md5FileNameGenerator())
.threadPoolSize(4)
.tasksProcessingOrder(QueueProcessingType.LIFO).build();
configuration_0 = new DisplayImageOptions.Builder()
.showStubImage(R.drawable.icon)
.showImageOnFail(R.drawable.icon)
.showImageForEmptyUri(R.drawable.icon).cacheInMemory()
.cacheOnDisc().displayer(new RoundedBitmapDisplayer(20))
.build();
mImagelLoader = ImageLoader.getInstance();

// 判断是否初始化,否则初始化
if (!mImagelLoader.isInited()) {
mImagelLoader.init(configuration);


}
}


  源码地址下载 https://github.com/nostra13/Android-Universal-Image-Loader   
 
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐