我使用Android Studio 2.2.3并使用values-swdp文件夹和dimens.xml文件来决定我的Android应用中的项目大小。
我尝试了两种模拟设备:
Nexus S API 25
使用API 13
(以下详细信息)
我在调用getResources().getDimension(R.dimen.something)
时获得了不同的值。
在做完
后我注意到了DisplayMetrics displayMetrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);
调用displayMetrics.xdpi
和displayMetrics.ydpi
会为这两个设备返回不同的值:
我的问题是为什么不同的API会为xdpi和ydpi返回不同的值?
谢谢!
1
Name: 04.0_Nexus_S_API_25
CPU/ABI: Google APIs Intel Atom (x86)
Path: ...\040_Nexus_S_API_25.avd
Target: google_apis [Google APIs] (API level 25)
Skin: nexus_s
SD Card: ...\040_Nexus_S_API_25.avd\sdcard.img
hw.dPad: no
runtime.network.speed: full
hw.accelerometer: yes
hw.device.name: Nexus S
vm.heapSize: 32
skin.dynamic: yes
hw.device.manufacturer: Google
hw.gps: yes
hw.initialOrientation: Portrait
image.androidVersion.api: 25
hw.audioInput: yes
image.sysdir.1: system-images\android-25\google_apis\x86\
tag.id: google_apis
showDeviceFrame: yes
hw.camera.back: emulated
hw.mainKeys: yes
AvdId: 04.0_Nexus_S_API_25
hw.camera.front: emulated
hw.lcd.density: 240
avd.ini.displayname: 04.0 Nexus S API 25
hw.gpu.mode: guest
hw.device.hash2: MD5:37a2ff6e511626ba3ceddec8264474be
hw.ramSize: 512
hw.trackBall: no
hw.battery: yes
hw.cpu.ncore: 2
hw.sdCard: yes
tag.display: Google APIs
runtime.network.latency: none
hw.keyboard: yes
hw.sensors.proximity: yes
disk.dataPartition.size: 512M
hw.sensors.orientation: yes
avd.ini.encoding: UTF-8
hw.gpu.enabled: yes
2
Name: 04.0_Nexus_S_API_13
CPU/ABI: ARM (armeabi)
Path: ...\Nexus_S_API_10.avd
Target: default [Default] (API level 13)
Skin: nexus_s
SD Card: ...\Nexus_S_API_10.avd\sdcard.img
hw.dPad: no
runtime.network.speed: full
hw.accelerometer: yes
hw.device.name: Nexus S
vm.heapSize: 32
skin.dynamic: yes
hw.device.manufacturer: Google
hw.gps: yes
hw.initialOrientation: Portrait
image.androidVersion.api: 13
hw.audioInput: yes
image.sysdir.1: platforms\android-13\images\
tag.id: default
showDeviceFrame: yes
hw.camera.back: emulated
hw.mainKeys: yes
AvdId: 04.0_Nexus_S_API_13
hw.camera.front: emulated
hw.lcd.density: 240
avd.ini.displayname: 04.0 Nexus S API 13
hw.gpu.mode: off
hw.device.hash2: MD5:37a2ff6e511626ba3ceddec8264474be
hw.ramSize: 343
hw.trackBall: no
hw.battery: yes
hw.cpu.ncore: 2
hw.sdCard: yes
tag.display: Default
runtime.network.latency: none
hw.keyboard: yes
hw.sensors.proximity: yes
disk.dataPartition.size: 800M
hw.sensors.orientation: yes
avd.ini.encoding: UTF-8
hw.gpu.enabled: no