Universal Image Loader cache -
i'm trying integrate universal image loader android app. has gridview , shows images acquired internet. implemented using arrayadapter loads images in getview() in usual way.
it works in terms of displaying picture correctly. found unexpected behavior in loading images memory cache.
- when activity launched, uil loads image internet or disc cache if exists. (of course, expected behavior.)
- scrolling down gridview until first column go out screen, , scroll top. in time, images @ first column loaded disc cache, instead of memory cache.
- then scrolling down , again. in time, images @ first column loaded memory cache.
i expect images loaded memory cache @ second time of displaying, step 2 in operation above. don't know why disc cache used in case.
here codes.
imageloaderconfiguration
imageloaderconfiguration mimageloaderconfig = new imageloaderconfiguration.builder(getapplicationcontext()) .defaultdisplayimageoptions(defaultoptions) .enablelogging() .build(); displayimageoptions
displayimageoptions defaultoptions = new displayimageoptions.builder() .cacheinmemory() .cacheondisc() .showimageforemptyuri(r.drawable.empty_photo) .showstubimage(r.drawable.empty_photo) .displayer(new fadeinbitmapdisplayer(500)) .build(); getview() in arrayadapter
if (convertview == null) { convertview = (framelayout) layoutinflater.from(getcontext()) .inflate(mlayoutid, null); convertview.setlayoutparams(mimageviewlayoutparams); } else { // otherwise re-use converted view convertview.findviewbyid(r.id.videoiconinthumbnail).setvisibility(view.gone); } // check height matches our calculated column width if (convertview.getlayoutparams().height != mitemheight) { convertview.setlayoutparams(mimageviewlayoutparams); } imageview image = (imageview) convertview.findviewbyid(r.id.photothumbnail); imageloader.getinstance().displayimage(thumbnailurl, image, new simpleimageloadinglistener() { @override public void onloadingcomplete(string imageuri, view view, bitmap loadedimage) { log.v(tag, imageuri + " loaded."); } }); return convertview; layout xml element in gridview
<?xml version="1.0" encoding="utf-8"?> <framelayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" > <imageview android:id="@+id/photothumbnail" android:layout_width="match_parent" android:layout_height="match_parent" android:scaletype="centercrop" > </imageview> <imageview android:id="@+id/videoiconinthumbnail" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center" android:src="@drawable/ic_play" android:visibility="gone" > </imageview> </framelayout> version of uil 1.8.4. tested android version 4.1.2.
added log output of uil when image loaded 3 times operation described above.
// fist time of displaying i/imageloader( 7404): start display image task [http://xxx/yyy.jpg_1080x1776] i/imageloader( 7404): load image disc cache [http://xxx/yyy.jpg_1080x1776] i/imageloader( 7404): subsample original image (x192) x192 (scale = 1) [http://xxx/yyy.jpg_1080x1776] i/imageloader( 7404): cache image in memory [http://xxx/yyy.jpg_1080x1776] i/imageloader( 7404): display image in imageview [http://xxx/yyy.jpg_1080x1776] // second time of displaying i/imageloader( 7404): imageloader paused. waiting... [http://xxx/yyy.jpg_358x357] i/imageloader( 7404): start display image task [http://xxx/yyy.jpg_358x357] i/imageloader( 7404): load image disc cache [http://xxx/yyy.jpg_358x357] i/imageloader( 7404): subsample original image (x192) x192 (scale = 1) [http://xxx/yyy.jpg_358x357] i/imageloader( 7404): cache image in memory [http://xxx/yyy.jpg_358x357] i/imageloader( 7404): display image in imageview [http://xxx/yyy.jpg_358x357] // third time of displaying i/imageloader( 7404): load image memory cache [http://xxx/yyy.jpg_358x357] thank you.
this because of uil's logic.
1) first time (imageloader.displayimage(...)) size of imageview unknown because haven't drawn yet on screen. uil considers size of imageview full screen size, decodes image bitmap of size (1080x1776, considering aspect ratio) , caches bitmap in memory.
2) second time real size of drawn imageview known (which smaller full screen size) , uil search cached bitmap of appropriate size cache contains previous large bitmap large our needs. uil decodes image again smaller bitmap , cache in memory too.
3) following displays uses cached bitmap of needed size.
so feature of uil. recommend use denycacheimagemultiplesizesinmemory() in configuration save memory.
Comments
Post a Comment