5

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.

lucian.pantelimon
  • 3,673
  • 4
  • 29
  • 46
Me Malik
  • 409
  • 2
  • 5
  • 13
  • 1
    Check [this](http://stackoverflow.com/questions/14215690/support-for-different-screen-sizes-in-android/14215922#14215922), [this](http://stackoverflow.com/questions/13098866/different-layouts-to-support-different-screens-in-android/13098895#13098895) and [this](http://stackoverflow.com/questions/12119344/how-to-create-an-android-application-that-support-and-run-perfect-all-screen-siz/12119475#12119475). – Hardik Joshi Dec 04 '13 at 09:14
  • Check out this.. [1]http://stackoverflow.com/questions/20117805/android-screen-sizes-support/20118104#20118104 – Joyal Dec 04 '13 at 09:18
  • check out this http://stackoverflow.com/questions/16706076/font-size-and-images-for-different-devices – Bhavesh Jethani Jul 24 '14 at 09:29

4 Answers4

6

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 !!

Mehul Joisar
  • 15,348
  • 6
  • 48
  • 57
  • But what about situations where you can't do this @MehulJoisar? Take 2 devices, both XHDPI, one with an XLarge screen and a max GL Texture size of 8192 and one with a large screen and a max texture size of 2048. There is a texture (png file) with a size of 4096 in the XHDPI folder. Both devices get the file from here, but the 2nd device with it's max texture size of 2048 can't display this texture. Therefore when the app runs, everything is just displayed as black boxes. How would you provide spearate resources for the two devices (so a 2048x2048 image for the smaller device) ? ? – Zippy Sep 12 '14 at 18:52
  • @Zippy: you can apply multiple qualifiers to achieve desired results, just create `drawable-large-xhdpi` and `drawable-large-xhdpi` . While looking for the image, it will checkout size qualifiers(large/xlarge) and then will checkout density qualifier(xhdpi). For reference kindly go through [this](http://developer.android.com/guide/practices/screens_support.html#qualifiers) – Mehul Joisar Sep 15 '14 at 04:45
  • Thanks @MehulJoisar yeah I've been trying this with XML aliases for a while now but it wasn't behaving as I would expect, let's say I provided a normal-xhdpi folder then an xhdpi device with an XLarge screen would still get its resources from the normal folder! However I think I've managed to figure it out, you ***have to*** provide a folder for every single possible size/DPI for this to work. Its a pain as I've had to create 12 extra folders each with an XML alias to files in the nodpi folder but at least I think its working now! – Zippy Sep 15 '14 at 12:10
  • @Zippy: android selects and `scales` the resources automatically based on precedence of qualifiers, if you provide the image for only normal-xhdpi folder, then other devices will get the image from that folder but it will get scaled automatically by android according to its density ratio. you can look at the documentation about the ratio. I would insist to use either 9patch or try to produce [multiple apks](http://developer.android.com/google/play/publishing/multiple-apks.html) to reduce the size – Mehul Joisar Sep 15 '14 at 13:05
  • Thanks @MehulJoisar, I read the documentation quite a few times, but I often find it confusing. However I do believe I have managed to resolve it by using aliases for my situation (thereby without providing extra bitmaps so, not increasing the APK size) - All I've done is put an alias to the smaller texture inside drawable-normal-xhdpi therefore, all devices with this configuration will pick up the smaller bitmap to use for the texture. I'm confident from looking at various specs that most 'large' or 'xlarge' screen xhdpi devices will support textures > 2048 (most seem to support 4096). – Zippy Sep 15 '14 at 13:42
  • However, if it does become a problem in the future, I will definitely look into using a separate APKs for tablets, if it's possible :-) – Zippy Sep 15 '14 at 13:47
  • @Zippy: I'm glad to help. In case, you want to distinguish for different screen sizes, [this documentation](http://developer.android.com/guide/topics/manifest/supports-screens-element.html) will be helpful. – Mehul Joisar Sep 15 '14 at 13:54
2

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

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

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.

InnocentKiller
  • 5,234
  • 7
  • 36
  • 84
  • lets suppose i have an image test.png test.png (25 * 25) for small device test.png (35 * 35) for noral device test.png (45 * 45) for large device now I have to put ldpi images fro all screen sizes in drawable-ldpi folder.can you please tell me how many image I have to put in drawable-ldpi folder .It ll not be a conflict we can past more then one image with same name in same folder how we can keep low desnity image for all screen sizes in one folder or is there any other way? ??? – Me Malik Dec 05 '13 at 06:31
0

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

Kevin van Mierlo
  • 9,554
  • 5
  • 44
  • 76
  • "all my images in one folder (usually xhdpi)" it is not a good idea. I agree Android scale down drawable but that scaling takes time (which can slow your app) and sometime app can crash if images are of very high resolution – Androider May 19 '14 at 04:53
  • @pokerface I never experienced app crashes before and made a lot of apps. A problem I'm experiencing is that I just don't know what to do with the other sizes. Cause I make one image (hdpi usually) and then I don't know how to scale it down for lower resolutions – Kevin van Mierlo May 19 '14 at 11:13
  • Yes but if you let Android re-scales all your images, if you have many pictures on every activity, you will get an OutOfMemory exceptions... – Hubert Solecki Aug 14 '15 at 09:11
  • @HubertSolecki The pictures get rescaled the moment the user installs the app or when the apk is made. Forgot which one it was. Definitely doesn't do it in realtime. I've been using this method a few years now. So far no problems – Kevin van Mierlo Aug 14 '15 at 09:25
  • @KevinvanMierlo I think that you have more experience than me if you develop on Android since few years but I've faced the following issue yesterday: [here]http://stackoverflow.com/questions/16445635/galaxy-s4-and-maybe-all-hd-phones-out-of-memory-error-inflating-layout . I'm developing my App on a Nexus 7 and had all my pictures in a drawable folder. But I've tested on Nexus 5 and the App became slow, buggy and crashes because of OutOfMemory Exceptions... Apparently, when it inflates a ImageView containing a Drawable, it re-scales it at that moment... When you have too many pictures > crashe – Hubert Solecki Aug 14 '15 at 09:37
  • @HubertSolecki The reason is not because you only put images in the hdpi folder. So there is another problem somewhere in your code. Probably because your `ImageView` is smaller than your image. If your image is really huge than an OOM could occur. If you google you can probably find ways to make your image smaller to avoid OOM's – Kevin van Mierlo Aug 14 '15 at 14:34