目前我正在使用百分比来维护我的 Android 应用程序 UI,但我认为这不是最好的解决方案。
我在文档中找到了这个:
The coordinates grid
Titanium uses a grid coordinate system for layout. Grid locations are based on the system unit (platform-dependent unit). This means that by default on iOS, elements are positioned on a density-independent grid and on Android on a density-dependent grid. The net result is that on iOS, elements are positioned in visually the same locations regardless of the actual density of the screen. On Android, elements are positioned at the same absolute pixel locations and might lay out differently depending on the device.
iPhone with either original or retina display is based on a 320 x 480 dip grid.
iPad is based on a 1024 x 768 dip grid.
Android device screen sizes vary. Considering these emulator examples:
HVGA emulator is 320 x 480 px
WVGA800 emulator is 480 x 800 px
WVGA854 emulator is 480 x 854 px
Remember that you can specify dp or dip units on Android (and even set an app-level default in tiapp.xml) to achieve the same density-independent grid as offered by default on iOS.
我认为,最后一句话应该意味着如果我将 tiapp.xml 中的应用程序级别默认设置为 dp 或 dip,那么我应该有一个 320 px (dip) 宽度的坐标网格......但是当我启动我的应用程序时,窗口和视图宽度是 360... 为什么?问题出在哪里?
这些是我设备的一些 displayCaps 信息。
[INFO] : Ti.Platform.displayCaps.density: xxhigh
[INFO] : Ti.Platform.displayCaps.dpi: 480
[INFO] : Ti.Platform.displayCaps.platformHeight: 1776
[INFO] : Ti.Platform.displayCaps.platformWidth: 1080
[INFO] : Ti.Platform.displayCaps.logicalDensityFactor: 3
[INFO] : Ti.Platform.displayCaps.xdpi: 442.45098876953125
[INFO] : Ti.Platform.displayCaps.ydpi: 443.3450012207031