java - Android Load Many Images Efficiently -
i have lot of png images contained in various drawable folders (drawable-xhdpi, drawable-mdpi, etc.) relatively small (at 10kb) @ 1 point need load 50 of them onto screen. when this, causes outofmemoryerror. ideally, able load these images calling setcontentview once (the content view has bunch of imageviews src attribute set corresponding images). that's i'm doing now, of course isn't working because of memory error. besides reducing size of images, there way prevent outofmemoryerror?
avoid loading number of images @ once, instead can load them in gridview
described here.
use picasso gridview
memory efficiency
public view getview(int position, view convertview, viewgroup container) { imageview imageview; if (convertview == null) { // if it's not recycled, initialize attributes imageview = new imageview(mcontext); imageview.setscaletype(imageview.scaletype.center_crop); imageview.setlayoutparams(new gridview.layoutparams( layoutparams.match_parent, layoutparams.match_parent)); } else { imageview = (imageview) convertview; } // load image imageview "using picasso" picasso.with(mcontext).load(imageresids[position]).into(imageview); return imageview; }
Comments
Post a Comment