What is the independent pixel density for a Galaxy s4?
I need it so I can have a qualifier sw???dp
for that phone.
It would be great if you could explain how to calculate it.
What is the independent pixel density for a Galaxy s4?
I need it so I can have a qualifier sw???dp
for that phone.
It would be great if you could explain how to calculate it.
Nobody answered the question: S4: Resolution 1080 x 1920 pixels (~441 ppi pixel density) per gsmarena formula: px = dp * (dpi / 160) from Google's article on "Supporting multiple screens". Therefore: dp = px / (dpi / 160). So, shortest width (sw) = 1080/(441/160) = 391
As also stated here: Use size and density-specific resources problems in Android app design
Here you can find how to calculate sw???dp
for every device you want.
Application Skeleton to support multiple screen
I think that instead of 96 x 5' (screen size) you should use these qualifiers: http://developer.android.com/design/style/devices-displays.html (160, 240, 320, 480). In this case of Galaxy S4, you get the good result, but if you try for example with a Nexus4 (4,7 ') you will get sw~272
instead of 380
as it should, and as happens in practice. This is the value you should use in your formula and you will get the right result.
OR
run this snippet code: (API 13+)
int sw = getResources().getConfiguration().smallestScreenWidthDp;
You can always find it in gsmarena.
For other unknown phones here's the formula for calculating the dpi:
dpi = ( square_root ( horizontal_pixels ^ 2 + vertical_pixels ^ 2 )) / ( screen_size )
In the case of galaxy s4:
Then
dpi = ( square_root ( 1080 ^ 2 + 1920 ^ 2 )) / 5.0
dpi = ( square_root ( 1166400 + 3686400 )) / 5.0
dpi = ( square_root ( 4852800 )) / 5.0
dpi = ( 2202.91 ) / 5.0
dpi = 440.5
dpi = 441 dpi