2016-03-04 30 views
0

目前我使用百分比來維護我的Android應用UI,但我認爲這不是最好的解決方案。所有Android設備的一個座標網格(Appcelerator)

我發現這個文檔中:

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或浸的話,我應該有一個座標網格與320像素(dip)寬度...但是當我啓動我的應用程序,Windows和視圖寬度是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 

回答

0

在Android displayCaps.platformWidthHeight總是以像素爲單位報到,而iOS上,他們總是在DP。 (來源:docs)。

ti.ui.defaultunit是什麼設置確定當您使用數字來表示屬性時使用的單位是什麼,如width:100。您始終可以使用像width:'100px'這樣的字符串強制一個單位。

它總是最好使用dp,以便獨立於設備的dpi,大小將大致相同。