Search code examples
androidandroid-layoutandroid-drawableandroid-resolution

how to use drawable to compatible with all screen sizes (idpi, mdpi, hdpi, xhdpi, xxhdpi)


Hello I am new in android programing so I want to know:

How to use drawable to compatible with all screen sizes (idpi, mdpi, hdpi, xhdpi, xxhdpi)

Actually I am confused about drawable screen sizes compatibility with all screen sizes

so I want to know that:

If I want my app to compatible with all screen size do I need to put images in every drawable folder

for example: background image

  • • drawable-ldpi ( 240x320 for QVGA Device 2.7 ) put image with this resolution
  • • drawable-mdpi ( 320x480 for HVGA Device 3.2 ) put image with this resolution
  • • drawable-hdpi ( 480x800 for WVGA Device 4.0 ) put image with this resolution
  • • drawable-xhdpi ( 1280x720 for WxVGA Device 4.7) put image with this resolution
  • • drawable-xxhdpi ( 1080x1920 for Nexus 5 Device ) put image with this resolution

or I can use a single same image for all screen sizes.


Solution

  • You do not need to create an image in every possible drawable folder. It's enough to provide one image only and put it into drawable folder. This image will be scaled automatically, depending on your usage.

    This will not provide good quality on all screens though and may be more expensive to compute (scale). It is recommended that you can provide separate images for different screen densities (e.g. drawable-mdpi, drawable-hdpi, etc.) and the idea is that they should have different resolutions matching the screen densities.