下载ImageLoader.jar
下载地址:http://code.google.com/p/libs-for-android/wiki/ImageLoader
ImageLoader初始化配置信息
- //图片保存系统路径
- File cacheDir = StorageUtils.getOwnCacheDirectory(context, "topnews/Cache");
- DisplayImageOptions imageOptions = new DisplayImageOptions.Builder().cacheInMemory().cacheOnDisc()
- .build();
- //一些相关的设置
- ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(MainActivity.this).threadPoolSize(5)
- .threadPriority(Thread.NORM_PRIORITY - 1).tasksProcessingOrder(QueueProcessingType.LIFO).denyCacheImageMultipleSizesInMemory()
- .memoryCache(new LruMemoryCache(1024 * 1024)).memoryCacheSize(1 * 1024 * 1024).discCache(new UnlimitedDiscCache(cacheDir)) // default
- .discCacheSize(20 * 1024 * 1024).discCacheFileCount(400).discCacheFileNameGenerator(new HashCodeFileNameGenerator()) // default
- .imageDownloader(new BaseImageDownloader(MainActivity.this)) // default
- .imageDecoder(new BaseImageDecoder()) // default
- .defaultDisplayImageOptions(imageOptions) // default
- .enableLogging().build();
- //初始化配置
- ImageLoader.getInstance().init(config);
调用的时候:
1.private ImageLoader imageLoader = ImageLoader.getInstance();
//ImageView对象用于显示图片
2. ImageView imageView = (ImageView) findViewById(R.id.imageView1);
//显示图片
3. imageLoader.displayImage("http://www.nichuwocai.com/Uploads/Avatar/s_avatar.gif", imageView);