0

I am about to publish an android application which uses several images with different resolutions. I have found the hard way (with a crash) that putting all images in drawable folder causes a OutOfMemory Exception because images are scaled up. By putting all images in a high dpi folder like drawable-xxhdpi the problem goes away.

My question is : should I arrange images according to their resolution to the respective folders ? Will that make any difference ? Will android scale-down an image found in drawable-xxhdpi even if it is a low resolution one ?

sotiris
  • 315
  • 6
  • 13
  • 2
    Use density-specific directories (e.g., `res/drawable-hdpi/`) for cases where you have multiple editions of the same image that support different densities. If you have images with only a single density, put them in `res/drawable-anydpi/`, to tell Android to use the image for any density. – CommonsWare May 29 '21 at 18:39
  • anydpi was added in API Level 21. what if I want to use API Level 16 ? – sotiris May 30 '21 at 06:46
  • API Level 21 (Android 5.0) is 7 years old. I do not recommend supporting older than that. That being said, `res/drawable-nodpi/` should suffice for older devices. – CommonsWare May 30 '21 at 10:41

1 Answers1

0

You may want to use Glide for rendering drawable in your app. Glide provides you mean to auto scale the images according to your image holder size. This also caches the images for faster access (if you were to use network images). Read the doc and see if it helps you.

exilour
  • 516
  • 5
  • 12