Titanium android 基于 textview 的 zindex 不良行为#appcelerator

Titanium android textview based zindex bad behavior #appcelerator

我的代码在 iOS 中有效,但在 android 中无效。

我有几个视图,其中设置按钮使视图可见且具有更高的 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 中,第二个视图部分出现

如果您尝试通过某个按钮事件将新视图置于另一个视图之上,请尝试使用以下代码:

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();

在第一个视图中您没有设置任何大小,因此它将默认填充其父视图。在第二个视图中,您将宽度设置为 250,将高度设置为 80。那么您在屏幕截图中看到的不正是您所设置的吗?如果您希望第二个也采用全尺寸,请删除 width/height.