Android different screen size and different densities

6.8k views Asked by At

I have to manage different screen sizes and different densities in my Android app. I am not getting directory structure properly.

What I understand so far is there are four types of screen sizes:

  1. small
  2. normal
  3. large
  4. xlarge

and different densities as well:

  1. ldpi
  2. mdpi
  3. hdpi
  4. xhdpi

Now each device size (small , normal , large and xlarge) shall map against each density. Because every size can have different density, right? If yes, then we can say small screen have all the density i.e ( ldpi , mdpi , hdpi , xhdpi) same for normal, large and xlarge.

The point is how I'll manage them in my drawable directories. Will there be four folders for small screen size with different size (drawable-small-ldpi, drawable-small-mdpi, drawable-small-hdpi, drawable-small-xhdpi)?

And same for other screen sizes as well.

If not then how I'll manage all the image in ( drawable-ldpi , drawable-mdpi , drawable-hdpi , drawable-xhdpi) folder because different screen size I'll have different size of images. Then how can a small device with different density and large device with a different size be manageable in same density folder.

Please don't give me reference of any Android document as I read all that stuff.

If any one can't get my point, then please let me know. I'm very confused.

4

There are 4 answers

7
Mehul Joisar On

When I have started development in Android, I was confused about same issue.But now I have figured it out and I'm doing pretty well.

Anyways, You are absolutely right.you can provide different images by 4 folders for each.i.e.: drawable-small-ldpi, drawable-small-mdpi, drawable-small-hdpi, drawable-small-xhdpi

But it is just waste of your time.because you don't need to worry this much about it.Android can scale up/scale down according to the device configuration.so just provide extra images for those devices only if you don't get desired outputs for them.

As far as I know, supporting multiple devices, you have to consider few general criteria in your mind.

Density qualifiers: ldpi,mdpi,hdpi,xhdpi,etc are generally used when you want to provide different resolution images.

Size qualifiers + Orientation qualifiers: small,normal,large,xlarge,sw600dp,normal-land,normal-port,etc are generally used when you want to provide different layout designs.

i.e.: single pane layout,multi-pane layout,different elements in layouts according to different screen sizes.

For reference: Download the example app from here and try to understand how it is being supported for multiple screens.

I hope it will be helpful !!

6
Kevin van Mierlo On

What I always do is just put all my images in one folder (usually xhdpi). The Android system will scale them for you so you don't have to worry about what to put in what folder.

Heres what Android says about this:

  • Provide different bitmap drawables for different screen densities

    By default, Android scales your bitmap drawables (.png, .jpg, and .gif files) and Nine-Patch drawables (.9.png files) so that they render at the appropriate physical size on each device. For example, if your application provides bitmap drawables only for the baseline, medium screen density (mdpi), then the system scales them up when on a high-density screen, and scales them down when on a low-density screen. This scaling can cause artifacts in the bitmaps. To ensure your bitmaps look their best, you should include alternative versions at different resolutions for different screen densities. The configuration qualifiers you can use for density-specific resources are ldpi (low), mdpi (medium), hdpi (high), and xhdpi (extra high). For example, bitmaps for high-density screens should go in drawable-hdpi/.

You can find the documentation here:

https://developer.android.com/guide/practices/screens_support.html

Hope this helps

0
Marcin Orlowski On

Here are official docs for you to read about the subject: Supporting Multiple Screens then Supporting Different Screen Sizes

1
InnocentKiller On

Put your all image in all different folder that is drawable-hdpi, drawable-ldpi, drawable-mdpi, drawable-xhdpi and drawable-xxhdpi. android will take care of it.