How to calculate the pixel density (dp) of a device?

What is the independent pixel density for Galaxy s4?

I need this, so I can have a qualifier sw???dpfor this phone.

It would be great if you could explain how to calculate it.

+4
source share
4 answers

Here you can find how to calculate sw???dpfor each device you want.

Multi-screen skeleton application

, 96 x 5 '( ) : http://developer.android.com/design/style/devices-displays.html (160, 240, 320, 480). Galaxy S4 , , , Nexus4 (4,7 '), sw~272 380, , , . , , .

: (API 13 +)

int sw = getResources(). getConfiguration(). smallestScreenWidthDp;

+3

: S4: 1080 x 1920 (~ 441 ) gsmarena : px = dp * (dpi/160) Google " ". : dp = px/(dpi/160). , (sw) = 1080/(441/160) = 391

: Android

+8

s4 ~ 441ppi, scale factor 441/160 = 2,75. , hdpi(1.5) xhdpi (2.0). xml values-xxhdpi.

You can also look here to look here for any further requests.

+4
source

You can always find it in gsmarena.

For other unknown phones, here is the formula for calculating dpi:

dpi = ( square_root ( horizontal_pixels ^ 2 + vertical_pixels ^ 2 )) / ( screen_size )

In the case of galaxy s4:

  • horizontal pixels = 1080
  • vertical pixels = 1920
  • screen size = 5.0

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
+1
source

All Articles