gonfy
gonfy

Reputation: 454

Scaling drawables for multiple screen densities

What is the recommended method for scaling images for each of the android drawable screen densities (hdpi, ldpi, xhdpi, ect.)? Should we use the source image resolution as the resolution for the highest density (xxhdpi) and scale from there? In my case I am explicitly setting the size of the image in the layout to 50 x 50 dp, so should I scale the drawable so that my mdpi is 50x50 and base the other resolutions around that?

PS: Why do we have to scale drawables manually if they will get scaled anyways when being placed (is it less efficient/clean?)

Upvotes: 2

Views: 1206

Answers (2)

Phantômaxx
Phantômaxx

Reputation: 38098

Should we use the source image resolution as the resolution for the highest density (xxhdpi) and scale from there? Yes: It's better that you prepare the highest resolution image/s and scale down, for a better quality.

In my case I am explicitly setting the size of the image in the layout to 50 x 50 dp, so should I scale the drawable so that my mdpi is 50x50 and base the other resolutions around that? Yes. Use the scale factor multiplier to determine the other resolutions sizes (0.75 for ldpi, 1 for mdpi, 1.5 for hdpi, 2 for xhdpi, 3 for xxhdpi, 4 for xxxhdpi)

Why do we have to scale drawables manually if they will get scaled anyways when being placed (is it less efficient/clean?) Yes. You can save Android from doing the scaling work (performances, at micro-level). And have a better overall quality (cleaner).

Upvotes: 3

Javier Enríquez
Javier Enríquez

Reputation: 630

The recommended method is having all folders:

  • drawable-ldpi
  • drawable-mdpi
  • drawable-hdpi
  • etc...

And having the drawable repeated in each folder with the corresponding resolution and the same name. Android will know which one will use based on device resolution. It will not scale them.

PS: If you have a right folder structure, your image will not be scaled programmatically. So it will be more efficient. Scaling a low res drawable in a high resolution device will result in a pixelated drawable. And viceversa it will look awful too.

Upvotes: 0

Related Questions