Reputation: 8375
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.
Upvotes: 6
Views: 28164
Reputation: 570
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
Upvotes: 3
Reputation: 773
Galaxy s4 has a density of about ~441ppi i.e so the scale factor
will come around 441/160=2.75. which is much higher than hdpi(1.5)
or xhdpi (2.0)
.Put your fonts xml in
values-xxhdpi
folder.
You can also have a look here look here for any further queries.
Upvotes: 5
Reputation: 297
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
Upvotes: 16
Reputation: 1928
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;
Upvotes: 5