2016-01-30 22 views
0

我的代碼在iOS中可用,但不適用於android。Titanium基於android textview的zindex不良行爲#appcelerator

我有幾個視圖,其中一個設置按鈕使視圖更高zindex可見。原來的觀點和我看到的第二個觀點都有文本字段。當我使第二個視圖可見時,只有一部分視圖如下所示。

original view 

original view with text view

second added view with higher zindex 

original view second view w/ higher zindex partially visible

原始視圖

var view = Ti.UI.createView({backgroundColor: '#F00',top: theTop}); 
T=Ti.UI.createView({backgroundColor:"#000",top:theTop}); 
var textfield = Ti.UI.createTextField({ 
    color: 'black', 
    height: '40dp', 
    top: '5dp', 
    left: '5dp', 
    right: '50dp', 
    style: Ti.UI.INPUT_BORDERSTYLE_ROUNDED, 
    hintTextColor:"black", 
    hintText: 'Enter an address', 
    backgroundColor: '#aaa', 
    zindex:"1", 
    paddingLeft: '5dp' 
}); 
代碼

爲第二視圖的代碼變得可見

E=Titanium.UI.createView({ 
    borderRadius:8, 
    backgroundColor:"red", 
    visible:"false", 
    zindex:"9999", 
    top:5, 
    left:5, 
    width:250, 
    height:80 
}); 

P=Ti.UI.createTextField({ 
    height:"30dp", 
    top:"8dp", 
    left:"8dp", 
    width:"200dp", 
    zindex:"9999", 
    style:Ti.UI.INPUT_BORDERSTYLE_ROUNDED, 
    hintText:"ET API key", 
    backgroundColor:"#fff", 
    paddingLeft:"5dp" 
}); 

再次,這工作正常的iOS,但Android的第二視圖部分出現

回答

0

在第一個視圖中,您不設置任何大小,因此它將默認填充其父項。在第二個視圖中,您將寬度設置爲250,高度爲80.那麼,您在屏幕截圖中看到的不是您設置的內容?如果你想要第二個也採取全尺寸,然後刪除寬度/高度。

+0

該代碼在iOS上工作,其中文本字段顯示在添加的視圖(如鏈接圖像中的結構)上,並且都顯示在原始視圖上方。 – petguy

+0

所以是的,第一個視圖填充父項,並有兩個文本字段(圖中顯示一個)。然後,當我點擊一個按鈕時,第二個視圖的一部分出現,顯示該視圖中的部分textview。我想要的是它如何出現在iOS中,整個第二個視圖出現在第一個視圖上。 – petguy

+0

謝謝Fokke,這不是一個糟糕的行爲,更多的是我很幸運,它在iOS中工作。我在您的評論之後再次查看了代碼,並意識到我在某些(但不是全部)維度中使用了「dp」。 iOS將它們全部解釋爲「dp」,但android是字面的,其中non-dp指向像素。再次感謝! – petguy

0

如果您正在試圖通過一些按鈕事件把一個新的觀點了另一種觀點,請嘗試使用下面的代碼:

var win = Ti.UI.createWindow({ 
backgroundColor : 'white' 
}); 

var view = Ti.UI.createView({ 
backgroundColor : '#EEE', 
height : Ti.UI.FILL, 
width : Ti.UI.FILL 
}); 
win.add(view); 
var view1 = Ti.UI.createView({ 
top: 0, 
backgroundColor : '#F00', 
height : 200, 
width : Ti.UI.FILL, 
}); 
view.add(view1); 
var textField1 = Ti.UI.createTextField({ 
borderStyle : Ti.UI.INPUT_BORDERSTYLE_ROUNDED, 
color : '#336699', 
width : '90%', 
height : '90%', 
style : Ti.UI.INPUT_BORDERSTYLE_ROUNDED, 
hintTextColor : "black", 
hintText : 'Enter an address', 
backgroundColor : '#aaa', 
zindex : "1", 
}); 
view1.add(textField1); 

var view2 = Ti.UI.createView({ 
top: 0, 
backgroundColor : '#0F0', 
height : 200, 
width : Ti.UI.FILL, 
}); 
var textField2 = Ti.UI.createTextField({ 
borderStyle : Ti.UI.INPUT_BORDERSTYLE_ROUNDED, 
color : '#336699', 
width : '90%', 
height : '90%', 
style : Ti.UI.INPUT_BORDERSTYLE_ROUNDED, 
hintTextColor : "black", 
hintText : 'Enter name', 
backgroundColor : '#aaa', 
zindex : "9999", 
}); 
view2.add(textField2); 

var button1 = Titanium.UI.createButton({ 
title: 'Hello', 
top: 600, 
width: 100, 
height: 50 
}); 
view.add(button1); 
button1.addEventListener('click',function(e) 
{ 
view1.hide(); 
view.add(view2); 
view2.show(); 
}); 

var button2 = Titanium.UI.createButton({ 
title: 'Hello1', 
top: 700, 
width: 100, 
height: 50 
}); 
view.add(button2); 
button2.addEventListener('click',function(e) 
{ 
view2.hide(); 
view1.show(); 
}); 

win.open(); 
+0

這已經看起來類似於我的代碼,它已經在iOS中工作,但不是在Android中。我不想隱藏第一個視圖來顯示第二個視圖,因爲通過調用view2.hide()和view1.show(),在窗口中還有其他視圖。雖然我的代碼已經在iOS上工作,但我會嘗試修改我的代碼以使用該方法而不是更改屬性。謝謝。 – petguy

相關問題