0

I didn't really understand the DP measure, even though I've read about it 2 times.

Let's say I have an image it's resolution is: 400 X 400 PX.

And I want to put it as background image to my app. and I'm putting the same image on the different drawable folders(ldpi,mdpi,...)

Would the image strech? I don't know what resolution the image should be on the different drawable folders so it will fit the devices.

Marcin Orlowski
  • 72,056
  • 11
  • 123
  • 141
idish
  • 3,190
  • 12
  • 53
  • 85

3 Answers3

3

Your base density is mdpi. So your 400x400 dp image will be rendered as is on mdpi devices only. If you want the same size on ldpi, you have to scale your image by 0.75. For hdpi your image needs to be 1.5 times bigger and for xhdpi devices, 2.0 times the size of your mdpi.

As mdpi is your base, I always put drawables in res/drawable-mdpi folder while developing. Once I got code ready for release I add hdpi resources to res/drawables-hdpi. I personally do not care ldpi devices as mostly no device I target is lower density than mdpi and if anyone will have such, then I am fine with android framework doing the downscale. But the upscaling is other story - you will always get bad results (blurry images) as you simply cannot technically make bigger bitmap from smaller without artifacts (no, CSI lies ;) - you simply got not enough data so you have to extrapolate. So it's better to provide proper drawables yourself or your end users would complain and your app may look not as nice as it could.

Marcin Orlowski
  • 72,056
  • 11
  • 123
  • 141
2

The idea is that the actual physical size of a displayed image will be different depending on the screen resolution.

On a mdpi device, screen density is about 1.5 dpi (dots per inch), which means that your 400px wide image will measure 2.5 inches.

If you want your image to be roughly the same size on a hdpi device (e.g 250 dpi), then you must provide a 625 pixel wide image (2.5*250). You shall put the image in the drawable-hdpi folder.

See this page for the description of the different densities.

sdabet
  • 18,360
  • 11
  • 89
  • 158
0

There are two important parameters which needs to taken cared when you are designing an app which
should run on multiple devices:

  • size(physical size of the device)
  • density of the device

Size: Size of a device in android is not defined as a unique physical value but as a range.
These are: small, normal, large and xlarge.

Density: Density is also defined as a range.
These are: ldpi, mdpi, hdpi and xhdpi.

enter image description here

For handling size you need to use have multiple layouts, one for each category of the size and you need to use different dp value for the height and width of the views for each of the layout as the sizeof a small and a large device will not be same.

For handling density you need to using different drawables for different screen densities i.e you need to place different density drawables in different drawable folders.
Eg:
These are the resolutions for a particular drawable

  • 36x36 for low-density (placed in drawable-ldpi)
  • 48x48 for medium-density (placed in drawable-mdpi)
  • 72x72 for high-density (placed in drawable-hdpi)
  • 96x96 for extra high-density (placed in drawable-xhdpi)

The ratio for this variation of the resolution is 3:4:6:8(ldpi:mdpi:hdpi:xhdpi)

For further reading you can refer to this android developer's link:
http://developer.android.com/guide/practices/screens_support.html

karn
  • 5,963
  • 3
  • 22
  • 29