1

I have done a lot of research but I feel I haven't quite understood the whole system of how to support different screen sizes.

So my designer wants to know which screen sizes I want to support and he wants to know which resolution to build for initially.

So I suggested that I wanted to support the following,

screen size normal
mdpi - yes hdpi - yes xhdpi - yes

So far I've assumed the following,

normal screen mdpi - 320x480 - 160ppi normal screen hdpi - 480x800 - 240ppi normal screen xhdpi - 640x960 - 320ppi

The problem is how do you define resources for a screen thats? 720x1280 ? Do I use resources defined for 640x960?

Something like the S3

Hades
  • 3,916
  • 3
  • 34
  • 74

4 Answers4

6

I already stated here application-skeleton-to-support-multiple-screen with designer perspective.

It is listed the percentage difference of device screen

Ldpi- 75%
Mdpi- 100%
Hdpi- 150%
XHdpi- 200%

But as we know now most of device coming with 480X800 so I'm consider this as based device, so our new calculation will like this

Ldpi- 50%
Mdpi- 66.67%
Hdpi- 100%
XHdpi- 133.33%

You can take XHdpi as based because when we enlarge smaller image then image gets blurred so start making artwork for bigger size and then to smaller.

Now about the devices which coming with High resolution 720x1280 i.e S3

you have qualifier with Smallest width concept(SW) introduced with Android V3.0 Honeycomb

drawable-sw???dp

Devices are categorized into screen width, so if we creating a folder named drawable-sw360dp then the devices with 720dp(either width or height) will use resource from this folder.

for example to find the Samsung Galaxy S3 dp to suffix drawable-sw?dp With reference of DP Calculation, If you want to support your layout or drawable to S3 then the calculation says

px= Device's width = 720
dpi= Device's density= 320

formula given

px = dp * (dpi / 160)

interchanging formula because we have px's value

dp = px / (dpi / 160)

now putting value,

 dp= 720 / (320/160);
 dp=360. 

so drawable-sw360dp will do the job for S3

Get you Device configuration from GsmArena, Same-way you can also create folder for different devices(awkward/latest ones)

You can also suffix the same value to your layout folder too layout-sw360dp

Community
  • 1
  • 1
Mohammed Azharuddin Shaikh
  • 41,633
  • 14
  • 96
  • 115
2

I also agree with other people who have posted the link to Supporting Multiple Screens on the Android Developer website, as it is a great resource to get to understanding the difference between the classes (small, normal, large) of screens and the different screen densities (ldpi, mdip, hdpi).

There is also a very interesting article on Metrics and Grids which has helped me out a lot.

You should also keep the scale of pixels to dip in the back of your head:

ldpi: 1dp = 0.75px, mdpi: 1dp = 1px, hdpi: 1dp = 1.5px and xhdpi: 1dp = 2px

I personally like to associate ldpi with a resolution of about 240x320, mdpi with 320x480, hdpi with 480x800 and xhdpi with anything larger, such as the SGS3.

The link to Metrics and Grids, for example, states that a button should be at least 48dp. This means that if you want to create a button with the size of 48x48, which translates to 48x48 px for mdpi, you also have to supply a graphic of 96x96 px for xhdpi, 72x72 px for hdpi and 36x36 px for ldpi.

I also suggest you and your designer take a look at 9-patch images and try to tweak your UI to this. This will make your life as a developer a lot less troublesome. The reason for this is that you can create small-sized images which can scale very nice throughout your app.

It's pretty obvious, you should try to create your graphics on the highest possible resolution (xhdpi for example) and then downscale to hdpi, mdpi and ldpi.

Another tip I came across, which I don't have the source to anymore, is to use the resource folder in Android, as it will be much better for performance, compared to only supplying a large image, and let the OS downscale it on the go. (But this SO post has some valid arguments in the answers)

Community
  • 1
  • 1
Ruben
  • 796
  • 3
  • 9
  • 21
0

You can use SVG library for vector graphics and very useful to support multi resolution screens the source code is here

Ali Imran
  • 8,927
  • 3
  • 39
  • 50
0

you should try something like this : For conversion from displayPixels to Pixels

(int)TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dp, context.getResources().getDisplayMetrics());

and for pixels to screenPixels

(pixels / context.getResources().getDisplayMetrics().scaledDensity);
lokoko
  • 5,785
  • 5
  • 35
  • 68