dimanche 19 avril 2015

Android loading drawable into ImageView taking a lot of memory

I'm having a problem.


I'm loading 9 drawables into 9 imageViews dynamically. (drawables are different each time) The drawable id is stored in the object class so when I load this drawable I set the ImageRessource to the imageView by using imageView.setImageRessource(myObject.getRessourceId()); Everything is working fine but when the 9 drawables are loaded, I see on the Android Memory Monitor that the allocate memory reaches 80MB and I think this isn't normal... (Is it?)


I tried different things to solve it:



  • Load the drawable with the library Picasso.

  • Use BitmapFactory.decodeResssource to create a Bitmap and then setImageBitmap on the imageView.


With all the techniques I tried, it takes 80MB of allocated memory.


I tried using different image resolution so in ldpi (~30Ko/image) and in xhdpi (~87Ko/image) but it doesn't change anything for each image loaded it takes about 5MB of allocated memory...


So my question is : How can I reduce the allocated memory for thoses images?


Thank you in advance, I can give parts of code if it's necessary.


Regards


PS: The ImageViews are created dynamically in the onCreate() method.


Aucun commentaire:

Enregistrer un commentaire