2

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.

ILYAS_Kerbal
  • 1,369
  • 11
  • 18
  • Those declarations have been deprecated for quite a while. See https://developer.android.com/guide/practices/screens_support.html#DeclaringTabletLayouts which is a bit obtuse (as much android API documentation is) for the "new" method. – alzee Jun 12 '17 at 00:28
  • @alzee which still does not answer the question – Code-Apprentice Jun 12 '17 at 00:50
  • 1
    Which is why it's posted as a comment and not an answer, @Code-Apprentice. – alzee Jun 12 '17 at 14:35

3 Answers3

2

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

Code-Apprentice
  • 81,660
  • 23
  • 145
  • 268
  • Clear and understandable. one more question: It's up to me to choose the initial size (in this case 48x48) for mdpi ? – ILYAS_Kerbal Jun 12 '17 at 02:54
  • 1
    @ILYAS_Kerbal for icons, material design specifies 48x48 for the base dimensions. For other assets, you have more flexibility. See https://material.io/guidelines/style/icons.html – Code-Apprentice Jun 12 '17 at 05:32
0

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

Varvara Kalinina
  • 2,043
  • 19
  • 29
0

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/

Atul Vasudev A
  • 463
  • 3
  • 22