Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android different screen size and different densities [duplicate]

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.

like image 373
Me Malik Avatar asked Dec 04 '13 09:12

Me Malik


People also ask

How did you handle the requirement of supporting different screen sizes in Android?

The best way to create a responsive layout is to use ConstraintLayout as the base layout in your UI. ConstraintLayout enables you to specify the position and size of each view according to spatial relationships with other views in the layout. All the views can then move and resize together as the screen size changes.

What are the four different densities followed by Android?

The configuration qualifiers you can use for density-specific resources are ldpi (low), mdpi (medium), hdpi (high), and xhdpi (extra high).

Why is it problematic to different sizes using pixels on Android?

The first pitfall you must avoid is using pixels to define distances or sizes. Defining dimensions with pixels is a problem because different screens have different pixel densities, so the same number of pixels may correspond to different physical sizes on different devices.


2 Answers

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

like image 187
Mehul Joisar Avatar answered Oct 05 '22 22:10

Mehul Joisar


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

like image 26
Marcin Orlowski Avatar answered Oct 06 '22 00:10

Marcin Orlowski