简体   繁体   English

为什么我的Android模拟器和Android手机在设备密度和DPI上给我不同的结果?

[英]Why does my android emulator, and my android phone give me different results for a devices density and DPI?

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: 在我的Lg G stylo h634上,其分辨率为(720 * 1280),尺寸为5.7英寸,实际PPI为258。使用此信息,此手机应该具有:

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. 现在,当我以相同规格运行手机的仿真版本时,会给出第一个指标(密度:1.5,PPI:240等),它们是适当的指标。 I'm not sure why this is happening, but can anybody explain why an emulated version is more accurate than the real device? 我不确定为什么会这样,但是有人可以解释为什么仿真版本比真实设备更准确吗?

Its not always about the DPI and PPI. 它并不总是与DPI和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. 在更多的物理设备上,与仿真器相比,等效规格之一的结果相差不大。

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. DisplayMetricsxdpiydpi是实际的物理密度值。 For example, the documentation for xdpi has : 例如, xdpi的文档包括

The exact physical pixels per inch of the screen in the X dimension. X尺寸屏幕每英寸的确切物理像素。

In your question, you state that the device has "a real PPI of 258". 在您的问题中,您声明该设备的“真实PPI为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. 请记住,像素很少是正方形的,因此这与您从DisplayMetrics获取的值xdpi ,因此xdpiydpi值很少完全相等。


The value for density is based on a manufacturer setting ( ro.sf.lcd_density in /system/build.prop , I think). density值基于制造商设置(我认为ro.sf.lcd_density中的/system/build.prop )。 Why LG decided to go with xhdpi instead of hdpi , I cannot say. 我不能说为什么LG决定使用xhdpi而不是hdpi 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). 另一个具有类似屏幕的制造商可能会选择hdpi (模拟器选择的内容)。

The value for densityDpi is driven directly from density . densityDpi的值直接由density驱动。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 为什么我的网站在Android模拟器和设备上看起来有所不同? - Why does my website look different in Android emulator and on devices? 如何将手机的密度与android -DPI目录图像匹配 - how to match my phone's density to android -DPI directory images android不是在我的手机上运行,​​而是在我的模拟器上运行 - android not running on my phone, but on my emulator does 为什么Netbeans无法与我的Android模拟器设备通信? - Why is Netbeans not communicating with my android emulator devices? Android adb devices 没有检测到我的手机 - Android adb devices does not detect my phone 为什么我的for循环在Android Studio中会产生与Eclipse相反的结果(java) - Why does my for loop give different results in Android studio oppose to eclipse (java) 在Android模拟器上模拟320 dpi的密度 - Emulating density of 320 dpi on android emulator Opengl es 2.0 - 为什么glFinish在我的新Android手机上给我的帧率低于旧手机? - Opengl es 2.0 - why does glFinish give me a lower framerate on my new android phone compared with an old one? 如何获取android sdk联系人选择器以仅给我电话结果而不是我所有的Twitter关注者 - How do get the android sdk contact picker to give me just phone results and not all my twitter followers 为什么我的 Android 仿真器无法启动? - Why my Android emulator does not start?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM