0

I was adding images after reading in the documentation:

This means that if you generate a 200x200 image for xhdpi devices, you should generate the same resource in 150x150 for hdpi, 100x100 for mdpi and finally a 75x75 image for ldpi devices.

So should my images in XHDPI be 200x200 pixels, my images in HDPI be 150x150 pixels, my images in MDPI be 100x100, and my images in LDPI be 75x75? After reading the documentation, that is what I thought, but when I came across this page:

Android background image size in pixel

The answers state to use different pixeol amounts for the different directories. I am very confused now on what to do. Here is what I have here right now, please tell me if I am doing this correct:

enter image description here

So basically, I spent the past 4-5 hours re-sizing lots of my images to the sizes in those folders. Now I'm thinking...did I even re-size them correctly? Is it supposed to be 100x100 for mdpi?

Basically, I just want to know if the directories are supposed to have that many pixels each. Because the question I linked says otherwise.

Thanks so much,

Ruchir

Community
  • 1
  • 1
Ruchir Baronia
  • 7,406
  • 5
  • 48
  • 83
  • Basically, I just want to know if the directories are supposed to have that many pixels each. Because the question I linked says otherwise. – Ruchir Baronia Jan 23 '16 at 05:53

2 Answers2

2

You did well to do what you did, if you actually want the images to be the size you scaled them to.

Let's review:

mdpi is the baseline density, of 160dpi. This means an image that's 160x160 pixels in mdpi will be one inch squared.

hdpi represents 240dpi. The same one inch square will need to be 240x240 pixels, or 1.5 larger than the mdpi asset.

xhdpi resolves 320dpi, so the square needs to be 320x320 pixels.

xxhdpi, at 480dpi brings the asset to 480x480 pixels.

xxxhdpi is only used for launcher images, so no worries there -- it is 640dpi.

We generally design in vector and then scale to hdpi, xhdpi and xxhdpi';mdpiis still relevant for some phone apps, but for tablets, it's virtually gone.ldpiis obsolete, with less than 3% of phones using it. Android will interpolate the closest image for the screen density, if an exact match is not available. For quick results,hdpiandxxhdpi` are sufficient.

Now note that the 200x200 for xhdpi is an example. Your pixel size will be different, based on what size you want the image to be. Take mdpi as a guide -- 40dp are 1/4 inch, 80dp are 1/2 inch, and so on. 40dp is the smallest decent hit-target, so I wouldn't make buttons smaller than that. Once you establish the size of your asset, you then scale it up -- 1.5x for hdpi, 2x for xhdpi and 3x for xxhdpi, and render your assets that way.

Size Inches   mdpi    hdpi   xhdpi  xxhdpi
       0.10      16     24      32      48
       0.25      40     60      80     120
       0.50      80    120     160     240
       1.00     160    240     320     480
       2.00     320    480     640     960

..and so on

323go
  • 14,143
  • 6
  • 33
  • 41
  • First off, I would like to thank you for your detailed answer. I am still very confused on this though. Are you saying that as long as you have proportions, it doesn't matter what your baseline is? What would those proportions be? Also, I don't really understand the point of all of this in the first place. Why can't I just use the `background` attribute rather than the `src` attribute for my imagebuttons, so that it will always be the right size? Would it be stretched out otherwise? Also, how would I find out the correct baseline, in order to expand it? Thanks so much! – Ruchir Baronia Jan 23 '16 at 06:30
  • Screens have different densities. I.e. a 7" tablet might have a 1024x600 screen, or a 1280x720 or a 2048x1200, etc. If your icons were all the same pixel size, then they'd appear much smaller on the higher resolution display. Android compensates for that by scaling the assets. In order to make them look as good as possible, and improve performance, you can include pre-scaled versions of the assets for different screen *densities*. src vs. background has nothing to do with size. – 323go Jan 24 '16 at 07:10
0

The XHDPI, HDPI, MDPI and LDPI directories are for different device screen densities, not different physical image sizes.

1 'density independent pixel' is defined as the physical size of 1 pixel on an MDPI (160 pixels per inch) device. For example, if you want a button to appear 2 inches wide, then the ImageButton layout_width attribute should be set to 2*160=320dp (device independent pixels), and the image in the MDPI directory should be 320px.

<ImageButton
    android:src="@drawable/my_button"
    android:layout_width="320dp"
    android:layout_height="160dp"/>

enter image description here

Devices with different screen densities will automatically look in the XHDPI, HDPI or LDPI directories for an image that matches the device screen density. For example, an XHDPI phone has twice as many pixels per inch as an MDPI phone, so the layout_width should still be set to 320dp (assuming you want it to appear 2 inches for all devices), but the image in the XHDPI directory should be 2*320=640px in order to match the density of the device (otherwise the image will appear blurry).

enter image description here

If you don't provide an image for the device's density, then Android will fall-back to using an image for one of the other densities. For example, here's what happens when an XHDPI device falls back on a LDPI image (still works, but the image used for the button is blurry in comparison to what the device is capable of):

enter image description here

anjsimmo
  • 704
  • 5
  • 18
  • Wait...So I don't need to change the size of my image? I'm really confused now...Whats the difference? Thanks so much! – Ruchir Baronia Jan 23 '16 at 07:17
  • If you want it to look perfect (no blurring) across a range of different different devices, then yes, you do need to export different image resolutions to each of the directories (as you have done). It's hard to explain without precise terminology for whether we are talking about physical size, image resolution, or density. This might help clear up some of the ambiguity: http://developer.android.com/guide/practices/screens_support.html – anjsimmo Jan 23 '16 at 07:30
  • Okay, I'm a bit confused on density vs physical size – Ruchir Baronia Jan 23 '16 at 07:36
  • Sorry, I can see that my statement about different densities, but the same physical image size may have been more confusing than helpful. I've added some images to help clear up what I was referring to. – anjsimmo Jan 23 '16 at 11:32