简体   繁体   中英

Density DPI of Samsung Galaxy S10 too small?

I've been getting device density like this:

val wm = getSystemService(Context.WINDOW_SERVICE) as WindowManager
val display = wm.defaultDisplay
val metrics = DisplayMetrics()
display.getMetrics(metrics)
val density = metrics.densityDpi

Then I based some logic on the value of density and constants:

  • DENSITY_XHIGH
  • DENSITY_XXHIGH

I expected S10 to fall under DENSITY_XXHIGH but apparently it's density value is 420 , contrary to S9 which density is 480 .

  1. Does that mean that S10 is actually using resources from xhdpi and not xxhdpi folder?
  2. If this value is not reliable what value should I base on my logic for choosing optimal image size before I load int into ImageView ?

If you want to know what is used, I suggest to create a "whoami" string and place it in values-xhdpi and all other *dpi variants.

values-xhdpi/whoami.xml

<resources>
    <string name="density_bucket" translatable="false">xhdpi</string>
</resources>

If you use that value, you know what the Android system selects from during runtime.

As this is a nice way for "debugging" your question to a specific device, you can also adopt to this. In my case this value is used to request the right image sizes from an asset backend.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM