36
votes

I've read 10 articles yet still cant find any relation between ldpi, mdpi, hdpi and the actual dimensions in pixels!? Can anybody give a straightforward answer please(if there is one!)

I'm basically trying to put together a splash screen that needs to work on multiple devices without stretching - but i'm struggling as everything I try is either squashed or stretched!?

Cheers Paul

7
I have the same doubt. I was struggled and searched many times, lot of websites still i can't get no one idea. Please post any one for straight answer here. Thanks @DancerSakthivel Appavu

7 Answers

76
votes

The ldpi, mdpi and hdpi refer to screen density, which means how much pixels can fit into a single inch.

the ratio in pixels between them is:

  • ldpi = 1:0.75
  • mdpi = 1:1
  • hdpi = 1:1.5
  • xhdpi = 1:2
  • xxhdpi = 1:3
  • xxxhdpi = 1:4

so lets take an image with about the size of 100X100:

  • for mdpi it should be 100X100
  • for ldpi it should be 75X75
  • for hdpi it should be 150X150
  • for xhdpi it should be 200X200
  • for xxhdpi it should be 300X300
  • for xxxhdpi it should be 400X400

this way, for screens with the same size but different DPI, all the images seem the same size on screen.

Also you have multiple screen size types small, normal, large, xlarge and each one of them can be ldpi, mdpi, hdpi, xhdpi, xxhdpi (Nexus 10) or xxxhdpi.

You can try to create a splash screen image that fit to each and every screen type which gives you 4*5 = 20 different images (it seems to much for me).

For now only the Nexus 10 is at the xxhdpi category.

24
votes

Install ImageMagick and use this shell script to generate your splash and icon files for multiple devices - iOS, Android, Bada and Windows Phone. You can use cygwin/gitbash if you are on Windows

I just did and I'm pretty happy with it :-)

The screen sizes are inside the script and are -

480x800 - screen-hdpi-portrait.png
320x200 - screen-ldpi-landscape.png
720x1280 - screen-xhdpi-portrait.png
320x480 - screen-mdpi-portrait.png
480x320 - screen-mdpi-landscape.png
200x320 - screen-ldpi-portrait.png
800x480 - screen-hdpi-landscape.png
7
votes

The definitions are:

  • xlarge screens are at least 960dp x 720dp. large screens are at least 640dp x 480dp. normal screens are at least 470dp x 320dp. small screens are at least 426dp x 320dp. (Android does not currently support screens smaller than this.)

Also, check out this blogpost from Dianne Hackborne: http://android-developers.blogspot.com/2011/07/new-tools-for-managing-screen-sizes.html

Probably the easiest thing is to use an image view and set the scaletype to CENTER_CROP. (Scale the image uniformly (maintain the image's aspect ratio) so that both dimensions (width and height) of the image will be equal to or larger than the corresponding dimension of the view).

Make sure that you use the src tag rather than setting the background.

<ImageView
   android:id="@+id/home_video_layout"
   android:src="@drawable/splash_image"
   android:layout_width="fill_parent"
   android:layout_height="wrap_content"
   android:scaleType="centerCrop"
   />

Updated:

Understanding Screen Densities and the “dp”

Resolution is the actual number of pixels available in the display, density is how many pixels appear within a constant area of the display, and size is the amount of physical space available for displaying your interface. These are interrelated: increase the resolution and density together, and size stays about the same. This is why the 320x480 screen on a G1 and 480x800 screen on a Droid are both the same screen size: the 480x800 screen has more pixels, but it is also higher density.

To remove the size/density calculations from the picture, the Android framework works wherever possible in terms of "dp" units, which are corrected for density. In medium-density ("mdpi") screens, which correspond to the original Android phones, physical pixels are identical to dp's; the devices’ dimensions are 320x480 in either scale. A more recent phone might have physical-pixel dimensions of 480x800 but be a high-density device. The conversion factor from hdpi to mdpi in this case is 1.5, so for a developer's purposes, the device is 320x533 in dp's.

3
votes

I have found this online dip <--> pixels calculator very useful.

https://pixplicity.com/dp-px-converter/

1
votes

I support previous answers but don't forget the power of Draw9Patch or using NinePatchDrawables

0
votes

These refer to screen pixel density, not screen dimension. You need to look into screen size specifiers like small, medium, large, and xlarge instead if you really need to change behavior based on screen size in pixels.

The Android docs explain what densities and sizes match these identifiers.

0
votes

Android devices can have different width-to-height ratios, while your image has a fixed one. If you do not want your image stretched, you will have to fill the blank spaces above and below or left and right.