sco*_*ott 11 android universal-image-loader
据我所知,universal-image-loader提供了两种显示图像的方法.imageLoader.loadImage和imageLoader.displayImage.但是这两个方法必须绑定到要显示的UI元素.我可以只在线程中下载缓存文件(以备将来显示).我现在不需要显示这些图像.
小智 12
你仍然可以使用UIL.根据displayOptions下面使用的图像将被缓存.
请参阅此处 - https://github.com/nostra13/Android-Universal-Image-Loader
//加载图像,将其解码为Bitmap并返回Bitmap以进行回调
imageLoader.loadImage(imageUri, displayOptions, new SimpleImageLoadingListener() {
@Override
public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) {
// Do whatever you want with Bitmap
}
});
Run Code Online (Sandbox Code Playgroud)
我可以只在线程中下载缓存文件(以备将来显示).我现在不需要显示这些图像.
您可以使用Executor下载文件或创建线程.您不需要使用通用图像加载器.
http://developer.android.com/reference/java/util/concurrent/Executor.html.
您也可以使用DownloadManager并将文件保存在SD卡中.您可以检索相同以供以后使用.
要缓存位图,您可以将图像写入sdcard中的文件夹.
缓存位图
http://developer.android.com/training/displaying-bitmaps/cache-bitmap.html.
您将位图缓存在内存或磁盘中.该链接包含有关该主题的详细信息.
你基本上使用UIL ofr在listview或grdiview中显示图像.要在listview或gridview中使用UIL,您可以执行以下操作.
https://github.com/nostra13/Android-Universal-Image-Loader.它基于Lazy List(基于相同的原理).但它有很多其他配置.如果下载失败,您可以显示错误图像.可以显示带圆角的图像.可以缓存在光盘或内存上.可以压缩图像.
在自定义适配器构造函数中
File cacheDir = StorageUtils.getOwnCacheDirectory(a, "your folder");
// Get singletone instance of ImageLoader
imageLoader = ImageLoader.getInstance();
// Create configuration for ImageLoader (all options are optional)
ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(a)
// You can pass your own memory cache implementation
.discCache(new UnlimitedDiscCache(cacheDir)) // You can pass your own disc cache implementation
.discCacheFileNameGenerator(new HashCodeFileNameGenerator())
.enableLogging()
.build();
// Initialize ImageLoader with created configuration. Do it once.
imageLoader.init(config);
options = new DisplayImageOptions.Builder()
.showStubImage(R.drawable.stub_id)//display stub image
.cacheInMemory()
.cacheOnDisc()
.displayer(new RoundedBitmapDisplayer(20))
.build();
Run Code Online (Sandbox Code Playgroud)
在你的getView()中
ImageView image=(ImageView)vi.findViewById(R.id.imageview);
imageLoader.displayImage(imageurl, image,options);//provide imageurl, imageview and options
Run Code Online (Sandbox Code Playgroud)
您可以配置其他选项以满足您的需求.
与延迟加载/通用图像加载器一起,您可以查看支架以实现平滑滚动和性能.http://developer.android.com/training/improving-layouts/smooth-scrolling.html.
| 归档时间: |
|
| 查看次数: |
16263 次 |
| 最近记录: |