android - 40+ ImageButtons on one screen? -
for last 10+ hours try large (40+) amount of images (in imagebutton format) on single android screen without out of memory errors. activity work on image picker coloring book app. images of various sizes in range of (500 1200)x(500 1200), pngs (if matters).
i have tried:
- horizontal scroll view images added code. result slow (i on ui thread) , consumes large memory space.
- horizontal scroll view images added code via asyncthread. result fast still consumes large memory space. i user experience of 1 most!
- grid view , list view - both choppy (testing on first nexus 7). memory usage better.
what considering
- view pager - first results better grid view performance perspective (i have not completed moment assess memory usage should better understand). yet, dislike user experience , prefer scrollable list of images.
- conversion of resources jpg (will rid of transparency byte?)
- downsizing images max 500x500px
none of solutions seems android photo gallery app available on devices. experience love mirror. no idea how done though :(
two questions.
- what best way such thing (40+ images scrollable on single screen) done? viewpager? scrollview asynctask , thought images resolution? have not tried yet?
- what memory limit should try keep below? looking @ android heap size on different phones/devices , os versions seems 256 mb, fair assumption?
thanks. have great weekend!
ps. on ios works charm when add buttons scroll view :(
some basic calculations reveals problem:
40+ images @ 1200x1200 = approx 57mb, comments correct need subsample (i.e. thumbnail) images or use library such universal image loader. converting jpg doesn't matter. compressed storage format, memory required display pixels remains same.
there android developers article on displaying bitmaps efficiently sample code. following steps covered in more detail in article android bitmap loading efficient memory usage.
the basic steps in loading large bitmap are:
- determine required size (from known size or determining size of target view).
- use bitmapfactory class bitmap’s size (set injustdecodebounds in bitmapfactory.options true).
- calculate subsampling value , pass bitmapfactory.options setting insamplesize.
- use bitmapfactory load reduced size bitmap.
Comments
Post a Comment