Universal Image Loader for Android 使用实例详解手机开发
view plain
copy span > -
以下为参照原文进行的翻译
1. Caching默认不可用. 启用需要对DisplayImageOptions进行如下配置:
2. // Create default options which will be usedfor every
3. // displayImage( ) call if no options will be passed to this method
4. DisplayImageOptions defaultOptions= new DisplayImageOptions.Builder()
5.
6. .cacheInMemory()
7. .cacheOnDisc()
8.
9. .build();
10. ImageLoaderConfiguration config= new ImageLoaderConfiguration.Builder(getApplicationContext())
11.
12. .defaultDisplayImageOptions(defaultOptions)
13.
14. .build();
15. ImageLoader.getInstance().init(config);// Do it on Application start
16. // Then later, when you want to display image
17. ImageLoader.getInstance().displayImage(imageUrl, imageView); // Default options will be used
or this way:
DisplayImageOptions options= new DisplayImageOptions.Builder()
.cacheInMemory()
.cacheOnDisc()
.build();
ImageLoader.getInstance().displayImage(imageUrl, imageView, options); // Incoming options will be used
18. 开启缓存后默认会缓存到外置SD卡如下地址(/sdcard/Android/data/[package_name]/cache).如果外置SD卡不存在,会缓存到手机.缓存到Sd卡需要在Manifest文件中进行如下配置
19. uses permission android:name= android.permission.WRITE_EXTERNAL_STORAGE /
20. UIL是如何为ImageView精确定义需要的Bitmap的尺寸?它会搜索如下参数
o 获取ImageView真实的 width和 height
o 获取 android:layout_width 和 android:layout_height 参数
o 获取 android:maxWidth and/or android:maxHeight 参数
o 从configuration (memoryCacheExtraOptions(int,int) option)获取 maximum width and/or height 参数
o 获取设备屏幕的 width and/or height
所以如果你知道ImageView的大约最大尺寸,就可以设置如下参数android:layout_width|android:layout_height or android:maxWidth|android:maxHeight 这样会有助于正确计算当前View所需要的Bitmap尺寸,并节约内存
如果你使用UIL时经常出现 OutOfMemoryError 那你可以尝试如下方法:
o 减少线程池大小 (.threadPoolSize( )). 1 5 isrecommended.
o 在显示选项中使用 .bitmapConfig(Bitmap.Config.RGB_565) . RGB_565模式消耗的内存比ARGB_8888模式少两倍.
o 配置中使用 .memoryCache(newWeakMemoryCache()) 或者完全禁用在内存中缓存(don t call .cacheInMemory()).
o 在显示选项中使用 .imageScaleType(ImageScaleType.IN_SAMPLE_INT) 或者.imageScaleType(ImageScaleType.EXACTLY).
o 避免使用 RoundedBitmapDisplayer.调用的时候它使用ARGB-8888模式创建了一个新的Bitmap对象来显示
对于内存缓存模式 (ImageLoaderConfiguration.memoryCache( ))你可以使用已经实现好的方法.
o 缓存只能使用强引用:
§ LruMemoryCache (Least recently used bitmap is deleted when cache size limit isexceeded缓存大小超过指定值时,删除最近最少使用的bitmap) Used by default for API = 9
o 缓存使用弱引用和强引用:
§ UsingFreqLimitedMemoryCache (Least frequently used bitmap is deleted when cachesize limit is exceeded删除最少使用bitmap)
§ LRULimitedMemoryCache (Least recently used bitmap is deletedwhen cache size limit is exceeded删除最近最少使用bitmap) Used by default for API 9
§ FIFOLimitedMemoryCache (FIFOrule is used for deletion when cache sizelimit is exceeded先进先出规则删除bitmap)
§ LargestLimitedMemoryCache (The largest bitmap is deleted when cache sizelimit is exceeded删除最大的bitmap)
§ LimitedAgeMemoryCache (Decorator. Cached object is deleted when its ageexceeds defined value缓存对象超过定义的时间后删除)
o 缓存只能使用弱引用:
§ WeakMemoryCache (Unlimited cache不限制缓存)
21. 本地缓存模式可以使用以下以实现的方法 (ImageLoaderConfiguration.discCache( )):
o UnlimitedDiscCache (The fastest cache, doesn t limit cache size不限制缓存大小) Used by default
o TotalSizeLimitedDiscCache (Cache limited by total cache size. If cache size exceedsspecified limit then file with the most oldest last usage date will be deleted设置总缓存大小,超过时删除最久之前的缓存)
o FileCountLimitedDiscCache (Cache limited by file count. If file count incache directory exceeds specified limit then file with the most oldest lastusage date will be deleted. Use it if your cached files are of about the samesize.设置总缓存文件数量,当到达警戒值时,删除最久之前的缓存。如果文件的大小都一样的时候,可以使用该模式)
o LimitedAgeDiscCache (Size-unlimited cache with limited files lifetime.If age of cached file exceeds defined limit then it will be deleted from cache.不限制缓存大小,但是设置缓存时间,到期后删除)
NOTE: UnlimitedDiscCache比其他方式快30%以上.
22. To displaybitmap (DisplayImageOptions.displayer( )) you can usealready prepared implementations:
o RoundedBitmapDisplayer (Displays bitmap with rounded corners)
o FadeInBitmapDisplayer (Displays image with fade in animation)
23. To avoid list(grid, ) scrolling lags you can use PauseOnScrollListener:
24. boolean pauseOnScroll= false; // or true
25. boolean pauseOnFling= true; // or false
26. PauseOnScrollListener listener= new PauseOnScrollListener(imageLoader, pauseOnScroll, pauseOnFling);
27. listView.setOnScrollListener(listener);
5815.html
app程序应用开发手机开发无线开发移动端开发相关文章
- android 浏览器 开发,Android 浏览器的开发实例分享
- android加密参数定位方法
- strictmode android,(十三)Android 性能优化 StrictMode
- unable to access android sdk add-on list解决方案[通俗易懂]
- 解决AMD CPU 启动Android模拟器时无法安装Intel HAXM 的问题
- android 定时器实例,Android定时器和Handler用法实例分析
- android viewpager实现轮播「建议收藏」
- Android SDK Tools_android.intent.category.DEFAULT
- 【Android 进程保活】应用进程拉活 ( 系统 Service 机制拉活 | Service 组件 onStartCommand 方法分析 | 源码资源 )
- 【Android 异步操作】Android 线程切换 ( 判定当前线程是否是主线程 | 子线程中执行主线程方法 | 主线程中执行子线程方法 )
- Android ConstraintLayout按比例缩放View详解手机开发
- [android] 看博客学习Android常见的几种RuntimeException详解手机开发
- 关于Android PullTorefreshScrollview回到顶部实例详解手机开发
- android Universal Image Loader for Android 说明文档 (1)详解手机开发
- Android系统与Linux之间的联系(android和linux)
- android开发教程之日历项目实践(一)
- Android中的Button自定义点击效果实例代码
- Android利用方向传感器获得手机的相对角度实例说明
- Android中实现多行、水平滚动的分页的Gridview实例源码
- Android数据库打包随APK发布的实例代码
- android获取手机IMSI码判断手机运营商代码实例
- Android轻松实现图片倒影效果实例代码
- Android中查看USB连接的外接设备信息的代码实例