0

On my Lg G stylo h634, it has a resolution of (720*1280) w/ a size of 5.7 inches and a real PPI of 258. With this information this phone should have:

DP width: 240
DP height: 240
Density: 1.5
Density PPI: 240

However when i run my test on this real device it's giving me:

DP width: 257
DP height: 258
Density: 2.0
Density PPI: 320

Now when i run an emulated version of my phone with the same specs, the first metrics are given (density: 1.5, PPI: 240, etc) which are the proper metrics. I'm not sure why this is happening, but can anybody explain why an emulated version is more accurate than the real device?

whompum
  • 69
  • 2
  • 12
  • 2
    Without the code that you are using to obtain these values, it is difficult to interpret them. – CommonsWare Jul 01 '17 at 20:29
  • DisplayMetrics #xdpi #ydpi #density #densityDpi <-Those are the only fields i'm using for both emulator and device – whompum Jul 01 '17 at 20:38

2 Answers2

2

Its not always about the DPI and PPI. The real phone comes with variety of hardware components. although the specs of real phone and emulator is same but real phone renders things differently also it scale things differently. My advice is try to run you app. on few more physical devices and compare to emulator one of equivalent specs result would not differ much.

GeekWithGlasses
  • 572
  • 2
  • 12
  • 30
  • 3
    @whompum if you follow traditional way you will be fine... if you want that much precise consistency try to do everything inrealtime. get the screensize programatically and manage things accordingly ... also use constraint layouts etc. just try out other ways ... poor layouting also affect the ui so keep that in in mind – GeekWithGlasses Jul 01 '17 at 20:55
  • 1
    Okay let me ask you this: As long as i follow the guidelines, and scale whitespace, could i reasonably assume that my UI will fit any SCREEN SIZE by using a few qualifiers (360 / 450 / 600 / 720 / 800), or is this a constant uphill battle? – whompum Jul 02 '17 at 13:34
  • 3
    if u follow guideline you will go fine. It not a up hill battle just make different layouts for different screen sizes that it. – GeekWithGlasses Jul 03 '17 at 18:09
  • @GeeksWithGlasses, thankyou very much for all of your input i'm sure you know this topic is slightly confusing until you play around with it enough. Thanks again :) – whompum Jul 03 '17 at 21:35
1

but can anybody explain why an emulated version is more accurate than the real device?

It's not. The device is what the device is.


On DisplayMetrics, xdpi and ydpi are the actual physical density values. For example, the documentation for xdpi has:

The exact physical pixels per inch of the screen in the X dimension.

In your question, you state that the device has "a real PPI of 258". That fits the values that you are getting from DisplayMetrics, bearing in mind that pixels are rarely square, so the xdpi and ydpi values are rarely exactly equal.


The value for density is based on a manufacturer setting (ro.sf.lcd_density in /system/build.prop, I think). Why LG decided to go with xhdpi instead of hdpi, I cannot say. If I had to guess, they felt that existing apps looked better on the device with that logical density. The emulator will use its own algorithm. Another manufacturer with a similar screen might choose hdpi (what the emulator chose).

The value for densityDpi is driven directly from density.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • is all this information regarding multi-screen support provided in your Busy Coders Guide? I'm looking for a decent resource on this information? – whompum Jul 02 '17 at 13:39
  • @whompum: I don't get into `DisplayMetrics` much, as most apps do not need it. `xdpi` and `ydpi` are important if you are doing something like rendering an on-screen ruler that needs to match the physical world. `density` and `densityDpi` are usually handled by resource sets (e.g., `res/drawable-hdpi/`) and dimensions (e.g., measuring things in `dp`, not `px`), more so than in Java code at runtime. I cover the tactical and strategic things that typical apps need to consider for dealing with different screen sizes and densities. – CommonsWare Jul 02 '17 at 13:55