Saturday, 12 July 2014

Android: Screen Densities, Sizes, Configurations, and Icon Sizes

1. Definitions

  • resolution = number of pixels available in the display, scale-independent pixel = sp
  • density = how many pixels appear within a constant area of the display, dots per inch = dpi
  • size = amount of physical space available for displaying an interface, screen's diagonal, inch
  • density-independent pixel = virtual pixel that is independent of the screen density, dp

2. Density Classes

ClassNameDensityFactorDrawable FolderComment
ldpilow density120 dpisp = 3/4 * dpdrawable-ldpi
mdpimedium density160 dpisp = dpdrawable-mdpi OR drawablebaseline size, example: 320x480 (sp or dp)
hdpihigh density240 dpisp = 1.5 x dpdrawable-hdpiexample: 480x800 sp = 320x533 dp
xhdpiextra high density320 dpisp = 2 x dpdrawable-xhdpi
xxhdpiextra extra high density480 dpisp = 3 x dpdrawable-xxhdpi
xxxhdpiextra extra extra high density640 dpisp = 4 x dpdrawable-xxxhdpi

3. Icon Sizes (full / content)

DensityLauncherMenuAction BarStatus Bar and NotificationTabPop-up Dialog and List ViewSmall and Contextual
ldpi36x36 px36x36 / 24x24 px24x24 / 18x18 px18x18 / 16x16 px24x24 / 22x22 px24x24 px12x12 / 9x9 px
mdpi48x48 px48x48 / 32x32 px32x32 / 24x24 px24x24 / 22x22 px32x32 / 28x28 px32x32 px16x16 / 12x12 px
hdpi72x72 px72x72 / 48x48 px48x48 / 36x36 px36x36 / 33x33 px48x48 / 42x42 px48x48 px24x24 / 18x18 px
xhdpi96x96 px96x96 / 64x64 px64x64 / 48x48 px48x48 / 44x44 px64x64 / 56x56 px64x64 px32x32 / 24x24 px
xxhdpi144x144 px(1)(1)(1)(1)(1)(1)
xxxhdpi192x192 px(1)(1)(1)(1)(1)(1)
  • (1) Google documentation says: "Applications should not generally worry about this density; relying on XHIGH graphics being scaled up to it should be sufficient for almost all cases."
  • Launcher icons for Android Market: 512x512 px.

4. Screen Size Classes

ClassSize in dpLayout FolderExamplesComment
small426x320 dplayout-smalltypical phone screen (240x320 ldpi, 320x480 mdpi, etc.)
normal470x320 dplayout-normal OR layouttypical phone screen (480x800 hdpi)baseline size
large640x480 dplayout-largetweener tablet like the Streak (480x800 mdpi), 7" tablet (600x1024 mdpi)
xlarge960x720 dplayout-xlarge10" tablet (720x1280 mdpi, 800x1280 mdpi, etc.)

5. Example Screen Configurations

Screen SizeLow density (120), ldpiMedium density (160), mdpiHigh density (240), hdpiExtra high density (320), xhdpi
smallQVGA (240x320)
normalWQVGA400 (240x400)
WQVGA432 (240x432)
HVGA (320x480)WVGA800 (480x800)
WVGA854 (480x854)
largeWVGA800 (480x800)(2)
WVGA854 (480x854)(2)
WVGA800 (480x800)(1)
WVGA854 (480x854)(1)

xlarge1024x600WXGA (1280x800)(3)
  • (1) To emulate this configuration, specify a custom density of 160 when creating an Android Virtual Device that uses a WVGA800 or WVGA854 skin.
  • (2) To emulate this configuration, specify a custom density of 120 when creating an Android Virtual Device that uses a WVGA800 or WVGA854 skin.
  • (3) This skin is available with the Android 3.0 platform.

6. Screen Orientation

OrientationNameLayout Folder, Example
landlandscapelayout-land-normal OR layout-land

7. Best Practices

  1. Use wrap_content, match_parent, or dp units when specifying dimensions in an XML layout file.
    • except for defining text sizes: sp (scaling depends on user setting)
    • Note: fill_parent is deprecated since API level 8.
  2. Do not use hard coded pixel values in your application code.
  3. Do not use AbsoluteLayout.
    • deprecated since Android 1.5
    • alternative: RelativeLayout
  4. Supply alternative bitmap drawables for different screen densities.
  5. Provide a launcher icon for xxhdpi, but no other icons.