Android Webview Vs. Imageview Performance To Display Images
Solution 1:
This may not directly answer your question, but have you tried using Volley's NetworkImageView
class ?
Recently, I used Volley
in a large project to display images, and it was faster and more stable than anything I've seen before. Volley is a networking library for Android developed by the good guys at Google, and it includes image downloading out of the box. It handles small or large images with ease. All you need to do is add the Volley library to your project and replace ImageView
in your XML layout with com.android.volley.toolbox.NetworkImageView
.
Add the following variables to your Activity
class:
private RequestQueue mRequestQueue;
private ImageLoader mImageLoader;
Create the objects in the onCreate()
method of your Activity
:
mRequestQueue = Volley.newRequestQueue(context);
mImageLoader = newImageLoader(mRequestQueue, newImageLoader.ImageCache() {
private final LruCache<String, Bitmap> mCache = newLruCache<String, Bitmap>(10);
publicvoidputBitmap(String url, Bitmap bitmap) {
mCache.put(url, bitmap);
}
publicBitmapgetBitmap(String url) {
return mCache.get(url);
}
});
Then download the image the getView()
method of your Adapter
class:
NetworkImageViewimage= (NetworkImageView)view.findViewById(R.id.image);
image.setImageUrl("http://somerandomurl.com/somerandomimage.png",mImageLoader);
In production code, you would use a global instance of both the RequestQueue
and ImageLoader
classes, and your onCreate()
method wouldn't be cluttered as it is here.
I wouldn't use a WebView
to display images, though of course it can be done. If you really want to see which way is "faster", you can try out ImageView
, NetworkImageView
and WebView
to load a large image and get a rough time estimate with the System.nanoTime()
method.
Post a Comment for "Android Webview Vs. Imageview Performance To Display Images"