androidlayerdrawable

LayerDrawable OutOfMemoryError


I need to load 20+ images on top of each other to form an interactive map where each layer can be turned on and off.

I decided to use a LayerDrawable for this, but I keep getting an OutOfMemoryError. Even after I set Large Heap to true, it'll be able to load about 8 images but any more than that it'll still throw the error.

Is there a way to load a lot of images into a LayerDrawable without getting that error, or is there a better way to do this?


Solution

  • Thanks to Luksprog's link I was able to fix the problem.

    I used inSampleSize to load a smaller version of each of the images before adding them to the Drawable[]. This cut down the amount of memory used by a lot.