Search code examples
androidresolutiondpi

Should we use the exactly DPI number to implement for multiple screen size?


I know we have some standard of DPI that we can use it for support multiple screen size in an like :

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

But when I calculate for some real device, e.g. LG G3 - it has DPI is 538.

So my question is do we need to use that exactly DPI number for scale the image,... or just let it be one of xxhdpi (480dpi) or xxxhdpi (640dpi).


Solution

  • For my opinion, I think you shouldn't care about information dpi of devices. You should only focus to provide images, size (dp,sp) etc for some type of screens :

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

    ========================================================================= Example: As you maybe known that 1 px = dp (dpi/160)

    So if you have an image with size is 32 x 32 px on screen 160 dpi. It's mean your image get size 32 x 32 dp.

    Now you want to scale it on xxhdpi (extra-extra-high) ~480dpi.

    On xxhdpi (extra-extra-high) ~480dpi : 1 px = dp(480/160) = 3dp

    Then you only need to provide another image with size 32*3 x 32*3 px = 96 x 96 px