# Universal Image Loader for Android
This project aims to provide a reusable instrument for asynchronous image loading, caching and displaying. It is originally based on [Fedor Vlasov's project](https://github.com/thest1/LazyList) and has been vastly refactored and improved since then.
**Download:** [JAR library](https://github.com/nostra13/Android-Universal-Image-Loader/downloads); [sources](https://github.com/nostra13/Android-Universal-Image-Loader/downloads) (you can attach it to project as _source attachment_ so you can see Java docs)
![Screenshot](https://github.com/nostra13/Android-Universal-Image-Loader/raw/master/UniversalImageLoader.png)
## Features
* Multithread image loading
* Possibility of wide tuning ImageLoader's configuration (thread pool size, HTTP options, memory and disc cache, display image options, and others)
* Possibility of image caching in memory and/or on device's file sysytem (or SD card)
* Possibility to "listen" loading process
* Possibility to customize every display image call with separated options
* Widget support
## Documentation
* Universal Image Loader. Part 1 - Introduction [[RU](http://nostra13android.blogspot.com/2012/03/4-universal-image-loader-part-1.html) | [EN](http://www.intexsoft.com/blog/item/68-universal-image-loader-part-1.html)]
* Universal Image Loader. Part 2 - Configuration [[RU](http://nostra13android.blogspot.com/2012/03/5-universal-image-loader-part-2.html) | [EN](http://www.intexsoft.com/blog/item/72-universal-image-loader-part-2.html)]
* Universal Image Loader. Part 3 - Usage [[RU](http://nostra13android.blogspot.com/2012/03/6-universal-image-loader-part-3-usage.html) | [EN](http://www.intexsoft.com/blog/item/74-universal-image-loader-part-3.html)]
### [Support](http://stackoverflow.com/questions/tagged/universal-image-loader)
First look at [Useful info](https://github.com/nostra13/Android-Universal-Image-Loader#useful-info).
If you have some question about Universal Image Loader you can ask it on [StackOverFlow](http://stackoverflow.com) with **[universal-image-loader]** tag. Also add **[java]** and **[android]** tags.
Bugs and feature requests place **[here](https://github.com/nostra13/Android-Universal-Image-Loader/issues/new)**.
### [Changelog](https://github.com/nostra13/Android-Universal-Image-Loader/commits/master)
## Usage
### Simple
``` java
ImageView imageView = ...
String imageUrl = "http://site.com/image.png"; // or "file:///mnt/sdcard/images/image.jpg"
// Get singletone instance of ImageLoader
ImageLoader imageLoader = ImageLoader.getInstance();
// Initialize ImageLoader with configuration. Do it once.
imageLoader.init(ImageLoaderConfiguration.createDefault(context));
// Load and display image asynchronously
imageLoader.displayImage(imageUrl, imageView);
```
### Most detailed
``` java
ImageView imageView = ...
String imageUrl = "http://site.com/image.png"; // or "file:///mnt/sdcard/images/image.jpg"
ProgressBar spinner = ...
File cacheDir = StorageUtils.getOwnCacheDirectory(getApplicationContext(), "UniversalImageLoader/Cache");
// Get singletone instance of ImageLoader
ImageLoader imageLoader = ImageLoader.getInstance();
// Create configuration for ImageLoader (all options are optional, use only those you really want to customize)
ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(getApplicationContext())
.memoryCacheExtraOptions(480, 800) // max width, max height
.discCacheExtraOptions(480, 800, CompressFormat.JPEG, 75) // Can slow ImageLoader, use it carefully (Better don't use it)
.threadPoolSize(3)
.threadPriority(Thread.NORM_PRIORITY - 1)
.denyCacheImageMultipleSizesInMemory()
.offOutOfMemoryHandling()
.memoryCache(new UsingFreqLimitedMemoryCache(2 * 1024 * 1024)) // You can pass your own memory cache implementation
.discCache(new UnlimitedDiscCache(cacheDir)) // You can pass your own disc cache implementation
.discCacheFileNameGenerator(new HashCodeFileNameGenerator())
.imageDownloader(new URLConnectionImageDownloader(5 * 1000, 20 * 1000)) // connectTimeout (5 s), readTimeout (20 s)
.defaultDisplayImageOptions(DisplayImageOptions.createSimple())
.enableLogging()
.build();
// Initialize ImageLoader with created configuration. Do it once on Application start.
imageLoader.init(config);
// Creates display image options for custom display task (all options are optional)
DisplayImageOptions options = new DisplayImageOptions.Builder()
.showStubImage(R.drawable.stub_image)
.showImageForEmptyUri(R.drawable.image_for_empty_url)
.cacheInMemory()
.cacheOnDisc()
.imageScaleType(ImageScaleType.POWER_OF_2)
.displayer(new RoundedBitmapDisplayer(0xff424242, 20))
.build();
// Load and display image
imageLoader.displayImage(imageUrl, imageView, options, new ImageLoadingListener() {
@Override
public void onLoadingStarted() {
spinner.show();
}
@Override
public void onLoadingFailed(FailReason failReason) {
spinner.hide();
}
@Override
public void onLoadingComplete(Bitmap loadedImage) {
spinner.hide();
}
@Override
public void onLoadingCancelled() {
// Do nothing
}
});
```
## Useful info
1. **Caching is NOT enabled by default.** If you want loaded images will be cached in memory and/or on disc then you should enable caching in DisplayImageOptions this way:
``` java
// Create default options which will be used for every
// displayImage(...) call if no options will be passed to this method
DisplayImageOptions defaultOptions = new DisplayImageOptions.Builder()
...
.cacheInMemory()
.cacheOnDisc()
...
.build();
ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(getApplicationContext())
...
.defaultDisplayImageOptions(defaultOptions)
...
.build();
ImageLoader.getInstance().init(config); // Do it on Application start
```
``` java
// Then later, when you want to display image
ImageLoader.getInstance().displayImage(imageUrl, imageView); // Default options will be used
```
or this way:
``` java
DisplayImageOptions options = new DisplayImageOptions.Builder()
...
.cacheInMemory()
.cacheOnDisc()
...
.build();
ImageLoader.getInstance().displayImage(imageUrl, imageView, options); // Incoming options will be used
```
2. How UIL define Bitmap size needed for exact ImageView? Search defined parameters top-down:
* Get ```android:layout_width``` or ```android:layout_height``` parameters
* Get ```android:maxWidth``` and ```android:maxHeight``` parameters
* Get maximum size parameters from configuration (```memoryCacheExtraOptions(int, int)``` option)
Set ```android:layout_width```|```android:layout_height``` or ```android:maxWidth```|```android:maxHeight``` parameters for ImageView if you know approximate maximum size of it. It will help correctly compute Bitmap size needed for this view and **save memory**.
3. If you often got **OutOfMemoryError** in your app using Universal Image Loader then try set WeakMemoryCache into configuration:
``` java
ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(getApplicationContext())
...
.memoryCache(new WeakMemoryCache())
...
.build();
```
4. For memory cache configuration (ImageLoaderConfiguration.Builder.memoryCache(...)) you can use already prepared implementations:
* UsingFreqLimitedMemoryCache (The least frequently used bitmap is deleted when cache size limit is exceeded) - Used by default
* LRULimitedMemoryCache (Least recently used bitmap is deleted when cache size limit is exceeded)
* FIFOLimitedMemoryCache (FIFO rule is used for deletion when cache size limit is exceeded)
* LargestLimitedMemoryCache (The largest bitmap is deleted when cache size limit is exceeded)
* LimitedAgeMemoryCache (Decorator. Cached object is deleted when its age exceeds defined val
没有合适的资源?快使用搜索试试~ 我知道了~
小程序源码 -Universal-Image-Loader-master.zip
共83个文件
java:52个
xml:17个
png:4个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 100 浏览量
2023-03-20
06:58:47
上传
评论
收藏 846KB ZIP 举报
温馨提示
免责声明:资料部分来源于合法的互联网渠道收集和整理,部分自己学习积累成果,供大家学习参考与交流。收取的费用仅用于收集和整理资料耗费时间的酬劳。 本人尊重原创作者或出版方,资料版权归原作者或出版方所有,本人不对所涉及的版权问题或内容负法律责任。如有侵权,请举报或通知本人删除。
资源推荐
资源详情
资源评论
收起资源包目录
小程序源码 -Universal-Image-Loader-master.zip (83个子文件)
Android-Universal-Image-Loader-master
UniversalImageLoader.png 390KB
UniversalImageLoaderExample
project.properties 360B
.classpath 364B
src
com
nostra13
example
universalimageloader
Extra.java 343B
BaseActivity.java 863B
HomeActivity.java 2KB
ImagePagerActivity.java 4KB
UILApplication.java 1KB
ImageGalleryActivity.java 2KB
ImageListActivity.java 3KB
widget
UILWidgetProvider.java 3KB
ImageGridActivity.java 3KB
libs
universal-image-loader-1.5.6-with-src.jar 102KB
android-support-v4.jar 219KB
res
anim
fade_in.xml 324B
menu
main_menu.xml 369B
xml
widget_provider.xml 265B
values
arrays.xml 8KB
strings.xml 998B
layout
item_list_image.xml 698B
item_grid_image.xml 333B
item_gallery_image.xml 369B
ac_home.xml 1KB
item_pager_image.xml 729B
ac_image_grid.xml 438B
ac_image_pager.xml 248B
widget.xml 1KB
ac_image_list.xml 229B
ac_image_gallery.xml 299B
drawable-hdpi
stub_image.png 2KB
image_for_empty_url.png 2KB
app_icon.png 4KB
AndroidManifest.xml 2KB
LICENSE 2KB
Jar
universal-image-loader-1.5.6-sources.jar 43KB
universal-image-loader-1.5.6.jar 61KB
UniversalImageLoader
project.properties 381B
src
com
nostra13
universalimageloader
utils
FileUtils.java 653B
StorageUtils.java 3KB
cache
disc
BaseDiscCache.java 1KB
naming
Md5FileNameGenerator.java 1KB
HashCodeFileNameGenerator.java 392B
FileNameGenerator.java 335B
impl
TotalSizeLimitedDiscCache.java 2KB
FileCountLimitedDiscCache.java 2KB
LimitedAgeDiscCache.java 2KB
UnlimitedDiscCache.java 1KB
DiscCacheAware.java 894B
LimitedDiscCache.java 4KB
memory
BaseMemoryCache.java 1KB
MemoryCacheAware.java 737B
LimitedMemoryCache.java 2KB
impl
UsingFreqLimitedMemoryCache.java 3KB
LimitedAgeMemoryCache.java 2KB
LRULimitedMemoryCache.java 2KB
FIFOLimitedMemoryCache.java 2KB
LargestLimitedMemoryCache.java 2KB
FuzzyKeyMemoryCache.java 2KB
WeakMemoryCache.java 628B
core
ImageDecoder.java 4KB
DisplayBitmapTask.java 1KB
assist
ImageSize.java 618B
MemoryCacheKeyUtil.java 1023B
FailReason.java 261B
SimpleImageLoadingListener.java 798B
ImageScaleType.java 612B
FlushedInputStream.java 891B
ImageLoadingListener.java 910B
DefaultConfigurationFactory.java 3KB
ImageLoadingInfo.java 1KB
DisplayImageOptions.java 5KB
ImageLoader.java 13KB
LoadAndDisplayImageTask.java 8KB
display
SimpleBitmapDisplayer.java 454B
BitmapDisplayer.java 746B
RoundedBitmapDisplayer.java 2KB
download
HttpClientImageDownloader.java 933B
URLConnectionImageDownloader.java 1KB
ImageDownloader.java 2KB
ImageLoaderConfiguration.java 17KB
AndroidManifest.xml 225B
.gitignore 104B
README.md 12KB
共 83 条
- 1
资源评论
荣华富贵8
- 粉丝: 221
- 资源: 7653
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 水沸腾了加热过程中水的变化记录表.docx
- 小红书运营工作职责.docx
- 学生社会实践活动鉴定表.docx
- 学生职业行动能力实践调查表.docx
- 学校绩效考核及绩效工资分配方案.docx
- 学校教导处工作计划.docx
- 医学院试卷保密室管理规定、保密室值班制度、医学院试卷保密室监控管理制度.docx
- 医学院试卷保密室钥匙使用承诺书.docx
- 印刷画册常见尺寸表.docx
- 运动素养与身心健康测评标准表.docx
- 渔业资源增殖放流实施方案.docx
- 智力残疾评定标准一览表.docx
- 制定 护理标准 制度.docx
- 中心学校学生住宿服务事项及安全管理情况.docx
- 中心小学课题管理办法.docx
- 中心学校劳动教育开展情况.docx
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功