2011-11-11 11 views
2

當我嘗試在鈦中添加100%高度的視圖時出現顯示問題 - 它在Android上正確顯示,但未在iOS上顯示。這裏有一個簡單的代碼: Android在鈦中添加100%高度的視圖在iOS上不起作用

結果在iPad上:在Android(正確)

Ti.UI.setBackgroundColor('#000'); 

var win = Ti.UI.createWindow({ 
    title:'win', 
    backgroundColor:'#fff' 
}); 

var s = Ti.UI.createView({ 
    width:'100%', 
    height:'100%', 
    backgroundColor:'red', 
    layout: 'horizontal' 
}); 

var r = Ti.UI.createView({ 
    backgroundColor:'yellow', 
    width:300, 
    height:'100%' // problem 
}) 

s.add(r); 

win.add(s); 
win.open(); 

結果 iPad

它的工作,如果我將高度設置爲一個有限的數字,但我希望視圖覆蓋整個高度。我該如何做到這一點,爲什麼在iOS上不能100%的高度工作?

+0

請注意,鈦平臺並不意味着用於構建應用程序只有一次。構建應用程序的最佳方式是構建1後端,併爲這兩個平臺創建一個不同的UI,以便更好地適應OS的目的。爲了在iPad上執行此操作,您還可以使用splitwindow:http://developer.appcelerator.com/apidoc/mobile/latest/Titanium.UI.iPad.SplitWindow-object.html –

回答

1

這可能與將view添加到view有關。如果將yellow view添加到window,並將zIndex添加到這兩個視圖中,它將正常工作。

對於對準它留下,你應該使用left: 0;,不layout: 'horizontal'作爲根據佈局屬性不存在的文件:http://developer.appcelerator.com/apidoc/mobile/latest/Titanium.UI.Window-object

var s = Ti.UI.createView({ 
    width:'100%', 
    height:'100%', 
    backgroundColor:'red', 
    zIndex: 1 
}); 

var r = Ti.UI.createView({ 
    backgroundColor:'yellow', 
    width:300, 
    height:'100%', // no problem 
    zIndex: 2, 
    left: 0 
}); 

win.add(r); 
+0

黃色視圖顯示在中心建議。如果我在窗口中添加'layout:'horizo​​ntal'',則什麼都不顯示。 – lzm

+0

加:'left:0',或者你會對。默認情況下,它將視圖或添加的任何內容居中。使用CSS樣式的頂部/底部/左/右,您可以正確定位它。這是高度和寬度的情況下 –

+0

此外,佈局屬性不顯示在文檔中:http://developer.appcelerator.com/apidoc/mobile/latest/Titanium.UI.Window-object。我更新了我的帖子以適應這個問題 –