Correct usage of Universal Image Loader

守給你的承諾、 提交于 2019-12-03 09:39:24
Raghunandan

You should consider using asynctask to get urls from the server.

You use should be using a view holder for smooth scrolling and performance. http://www.youtube.com/watch?v=wDBM6wVEO70. The talk is about view holder and listview performance.

http://developer.android.com/training/improving-layouts/smooth-scrolling.html

https://github.com/nostra13/Android-Universal-Image-Loader. Check the topic under Configuration and Display Options.

Instead of downloading it again you should cache images in phone memory or sdcard.

It caches images in say sdcard (if you have configured properly) using url as the key. If present display from cache else download, cache and display images.

In your custom adapter constructor

 File cacheDir = StorageUtils.getOwnCacheDirectory(activity context, "your folder");//for caching

 // 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()
.cacheInMemory(true)
.cacheOnDisk(true)
.showImageOnLoading(R.drawable.default_pic)//display stub image until image is loaded
.displayer(new RoundedBitmapDisplayer(20))
.build();

In your getView()

viewholder.image=(ImageView)vi.findViewById(R.id.imageview); 
imageLoader.displayImage(imageurl, viewholder.image,options);//provide imageurl, imageview and options.
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!