Screen densities and images dimensions

1.1k Views Asked by At

Hi Android developers,

I want to know how to choose the dimensions of drawables; for example, I have an image that I want to insert in my app, what size (pixel) the image should be to be inserted inside xxhdpi, xhdpi, hdpi, mdpi, and ldpi ?

I've analyzed many android apps on GitHub, they use random image sizes (pixel) for different densities.

3

There are 3 best solutions below

2
Code-Apprentice On BEST ANSWER

To create alternative bitmap drawables for different densities, you should follow the 3:4:6:8:12:16 scaling ratio between the six generalized densities. For example, if you have a bitmap drawable that's 48x48 pixels for medium-density screens, all the different sizes should be:

  • 36x36 (0.75x) for low-density
  • 48x48 (1.0x baseline) for medium-density
  • 72x72 (1.5x) for high-density
  • 96x96 (2.0x) for extra-high-density
  • 144x144 (3.0x) for extra-extra-high-density
  • 192x192 (4.0x) for extra-extra-extra-high-density

Source: https://developer.android.com/guide/practices/screens_support.html#DesigningResources

1
Varvara Kalinina On

I suggest you read this answer. It contains all information necessary to decide which units to use. TL;DR is: never use absolute values in pixels, instead, use dp units for views (including images), and sp for text.

Supporting multiple devices is covered here.

Also check the Material Design Guidelines to learn the commonly used dimensions for icons, margins, etc

0
Atul Vasudev A On

Easiest way is to use Android Asset Studio. It will generate all the required resolution of images for respective screen densities

https://romannurik.github.io/AndroidAssetStudio/