LayerDrawable makes a copy of the array you pass it; changing the original
array won't do anything.

That said, if you are running out of memory after loading 6 of your bitmaps,
you really need to make those bitmaps smaller.

On Mon, May 11, 2009 at 5:33 AM, Chris <[email protected]> wrote:

>
> I have a LayerDrawable consisting of 4 Drawables each representing a
> PNG. I get layers to change to different Drawables as desired, but
> only a few times. Then debugging will throw an OutOfMemoryError. It's
> as if the resource manager is not garbage-collecting once I replace
> each drawable. What am I mssing?
>
> Resources resources = getResouces();
> Drawable layer;
> Drawable[] layers = new Drawable[4]
>
> // Initialize the array of layers, omitted layer.setBounds(...) for
> readability
> layer = resources.getDrawable(R.drawable.graphic_1_a);
> layers[1] = layer;
> layer = resources.getDrawable(R.drawable.graphic_2_a);
> layers[2] = layer;
> layer = resources.getDrawable(R.drawable.graphic_3_a);
> layers[3] = layer;
> layer = resources.getDrawable(R.drawable.graphic_4_a);
> layers[4] = layer;
>
> // Apply the array to a LayerDrawable
> LayerDrawable layerDrawable = new LayerDrawable(layers);
>
> // Now changing a layer will work
> layer = resources.getDrawable(R.drawable.graphic_1_b);
> layers[1] = layer;
>
> // But then, ZygoteInit$MethodAndArgsCaller.run() throws
> OutOfMemoryError
> layer = resources.getDrawable(R.drawable.graphic_3_b);
> layers[3] = layer;
>
> >
>


-- 
Dianne Hackborn
Android framework engineer
[email protected]

Note: please don't send private questions to me, as I don't have time to
provide private support, and so won't reply to such e-mails.  All such
questions should be posted on public forums, where I and others can see and
answer them.

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to