0

This is a follow up question to this post. I have a header image on one of my screens and want to scale it to the full width but keeping the aspect ratio. So it should do something like this: Scaled Header image

I can do that, but now I have the problem that the image scales relatively bad. (Imagine some text on the picture above, this is not the best example). How can I provide several pictures in different resolutions to android so that android take the pictures which is best for the current screen size/density situation?

Community
  • 1
  • 1
Martin Böschen
  • 1,707
  • 15
  • 22
  • If the images that you begin with are small then upscaling will always be an issue. It's probably best to start with an image that is larger to begin with and if loading it into memory would be too intensive then downsize on the fly with `inSampleSize`. If you put duplicates of a file name in drawable density folders it will choose one automatically for you at runtime. – Jay Snayder Feb 25 '15 at 13:53

1 Answers1

0

Android support different screen densities through the use of configuration qualifier as follow:

  • ldpi (low) ~120dpi
  • mdpi (medium) ~160dpi
  • hdpi (high) ~240dpi
  • xhdpi (extra-high) ~320dpi
  • xxhdpi (extra-extra-high) ~480dpi
  • xxxhdpi (extra-extra-extra-high) ~640dpi

The best practice is to create a directory under the res/drawables/ directory with those qualifier. Eg.: /res/drawable/hpdi and store an image of the appropriate resolution in that folder. Do the same for the other qualifier; the proper image resolution will be chosen automatically based on the screen density of the device. Image filename must be the same in each of the configuration qualifier directory.

More info: Android Developers documentation.

A.L
  • 10,259
  • 10
  • 67
  • 98