Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid: Displaying many images , OutOfMemoryError
    primarykey
    data
    text
    <p>I have an app where I want to display images like in the BBC app.</p> <p><img src="https://i.stack.imgur.com/80GKe.png" alt="enter image description here"></p> <p>But I don't load them from a server, all pictures are in the res folder. There are at least 72 images (jpg), all ~512*340 (each ~10kB). All together have about 1MB.</p> <p>I want to display them in 340*225 and only show their full size if you click on them.</p> <p>I tried to implement this via XML and via Java alone, but i only get an outofmemory when there are displayed more than 12 images.</p> <p>I have searched for a solution for hours now and still havent found any. I read the android tutorial: <a href="http://developer.android.com/training/displaying-bitmaps/index.html" rel="nofollow noreferrer">http://developer.android.com/training/displaying-bitmaps/index.html</a> and many other stackoverflow questions, but they don't look suitable for my problem.</p> <p>How do i load the images into my activity? How can I resize them without wasting much RAM?</p> <p><strong>edit:</strong></p> <p>Now I load all images in my onCreate() :</p> <pre><code>ImageView ivDOK01 = new ImageView(this); ivDOK01.setImageBitmap(decodeSampledBitmapFromResource(getResources(), R.drawable.vo_dok01, 240, 164)); ivDOK01.setOnClickListener(this); ivDOK01.setMaxWidth(240); ivDOK01.setPadding(5, 5, 5, 5); ivDOK01.setAdjustViewBounds(true); </code></pre> <p>--> 72 times </p> <p>The setImageBitmap is from the android developer tutorial.</p> <p><strong>EDIT 2:</strong> With this method I can display 30 of the 72 images before I get the outofmemoryerror.</p> <p>But I would have a problem if images were a little bit bigger.</p> <p>Is there an option to only have the images in the RAM that are displayed? How does the normal Android Galery do that, where you can scoll fast over hundreds of images?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload