36

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

Dancer
  • 17,035
  • 38
  • 129
  • 206
  • 1
    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 @Dancer – Sakthivel Appavu Sep 15 '15 at 08:35

7 Answers7

76

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.

Felipe
  • 16,649
  • 11
  • 68
  • 92
Eitan
  • 1,012
  • 7
  • 25
  • Nexus 10 has a screen with ~299 ppi pixel density, which would fall on a xhpi device. To be an xxhpi device, it would need to have ~480ppi. But it needs an xxhpi icon launcher though. So, in fact, Nexus 10 is a xhdpi device, with a xxhdpi launcher icon. – Alesqui Sep 25 '13 at 20:40
25

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
Glorfindel
  • 21,988
  • 13
  • 81
  • 109
Peter
  • 4,493
  • 6
  • 41
  • 64
7

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.

Damian
  • 8,062
  • 4
  • 42
  • 43
  • 1
    Cheers for your help there - but i'm still confused! I still don't understand what actual dimension size (in pixels as I cant use DP in Photoshop?) I would make the image in Photoshop so that it could be displayed centre screen in each of the resolutions? Cheers Paul – Dancer Nov 17 '11 at 14:27
  • Did you read the blogpost I linked to? Just updated my answer with snippet from that article – Damian Nov 17 '11 at 14:49
3

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

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

Ridcully
  • 23,362
  • 7
  • 71
  • 86
1

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

Ewoks
  • 12,285
  • 8
  • 58
  • 67
0

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.

Sean Owen
  • 66,182
  • 23
  • 141
  • 173
0

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.

Witek
  • 6,160
  • 7
  • 43
  • 63