Monday 15 June 2015

android - Performance: use Webview to display images instead of ImageView -



android - Performance: use Webview to display images instead of ImageView -

in android activity, want display 10 images web. normally, have create 10 imageview display each image, imageview may cause out of memory exception. decide utilize 10 webview display image. worked great.

but don't know how performance of webview, can advise me how performance of 10 webviews , can utilize method display images?

webview occupies more space in memory image view . won't proper scaling in webview displaying images. webview can faster in popping image ui not efficient way .

you can seek volly has in build tool image downloading,caching , scaling , can insure quite fast also.

all need add together volley library project , replace imageview in xml layout com.android.volley.toolbox.networkimageview.

add next variables activity class:

private requestqueue mrequestqueue; private imageloader mimageloader; create objects in oncreate() method of activity: mrequestqueue = volley.newrequestqueue(context); mimageloader = new imageloader(mrequestqueue, new imageloader.imagecache() { private final lrucache<string, bitmap> mcache = new lrucache<string, bitmap>(10); public void putbitmap(string url, bitmap bitmap) { mcache.put(url, bitmap); } public bitmap getbitmap(string url) { homecoming mcache.get(url); } });

then download image getview() method of adapter class:

networkimageview image = (networkimageview)view.findviewbyid(r.id.image); image.setimageurl("http://someurl.com/someimage.png",mimageloader);

in production code, utilize global instance of both requestqueue , imageloader classes, , oncreate() method wouldn't cluttered in toy example.

i wouldn't utilize webview display images, though of course of study can done. if want see way "faster", can seek out imageview, networkimageview , webview load big image , rough time estimate system.nanotime() method.

android webview

No comments:

Post a Comment