Pregunta

I'm building an app with one image file that is used throughout the apps views. I'm a little confused about the information in android.developers in regards to scaling images to the different screen densities in Android: ldpi = 0.75; mdpi = 1.0; hdpi = 1.5; xhdpi = 2.0.

My first thought was that all I had to do was insert the image file to the appropriate density files, and Android would take care of the scaling thereafter; but I don't feel this is correct. My question is:

If I'm wrong, and I have to scale the image to the appropriate densities myself, and then save them to the different density files, how would I do this? Would I be able to do this in Photoshop? I'm thinking yes, but I'm not sure. If so, how would I scale an image? Thanks for any help!

¿Fue útil?

Solución

Here you go, this might help, I got it off of here, it comes in handy sometimes:

xlarge screens are at least 960dp x 720dp
large screens are at least 640dp x 480dp
normal screens are at least 470dp x 320dp
small screens are at least 426dp x 320dp

Generalised dpi values for screens:

ldpi resources for low-density (ldpi) screens (~120dpi)
mdpi resources for medium-density (mdpi) screens (~160dpi) (this is the baseline density)
hdpi resources for high-density (hdpi) screens (~240dpi)
xhdpi resources for extra high-density (xhdpi) screens (~320dpi)

Therefore generalised size of your resources (assuming they are full screen):

ldpi
Vertical = 426 * 120 / 160 = 319.5px
Horizontal = 320 * 120 / 160 = 240px
mdpi
Vertical = 470 * 160 / 160 = 470px
Horizontal = 320 * 160 / 160 = 320px
hdpi
Vertical = 640 * 240 / 160 = 960px
Horizontal = 480 * 240 / 160 = 720px
xhdpi
Vertical = 960 * 320 / 160 = 1920px
Horizontal = 720 * 320 / 160 = 1440px

Formula used:

px = dp*dpi/160

Otros consejos

If you want to let Android scale (which I don't recommend) you can simply place one image only in the appropriate density folder (preferably the highest you support -- xhdpi probably for now) and Android will scale it.

Preferably yes, you should rescale them beforehand in Photoshop/GIMP/editor of choice.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top