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.
Device-independent pixels (dp) For this mapping, 1 dp is considered to be equal to 1 pixel on a 160 dpi resolution screen. The corresponding number of pixels can be calculated with the formula px = dp * (dpi/160).
You can take either the horizontal or vertical resolution. Once you have the resolution, you must measure the length of the display. Usually, this will be measured in inches (2.54cm = 1 inch). If you divide the two numbers, you'll find the “pixels per inch” (ppi).
Finding Your DPI There are a handful of apps that can show you your DPI value, but the clear-cut best option is DPI Checker by TheViciousGames. It's super lightweight, open source, and does exactly what you need it to do and nothing more.
To preserve the visible size of your UI on screens with different densities, you must design your UI using density-independent pixels (dp) as your unit of measurement. One dp is a virtual pixel unit that's roughly equal to one pixel on a medium-density screen (160dpi; the "baseline" density).
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;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With