如何像滚动视图一样获得 windows 元素的过渡? [英] How to get a transition for windows element like in scroll views?

查看:25
本文介绍了如何像滚动视图一样获得 windows 元素的过渡?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在 Appcelerator 中制作一个演示,这是它的代码.

I am trying to make a Demo in Appcelerator here is the code for it.

var tabGroup = Titanium.UI.createTabGroup();

var main_win = Titanium.UI.createWindow({  
     title:'Tab 1',
     backgroundColor:'#fff'
});

var win1 = Titanium.UI.createWindow({  
     title:'Tab 1',
     backgroundColor:'#fff'
});
var tab1 = Titanium.UI.createTab({ 
     title:'Tab 1',
     window:win1
});
var label1 = Titanium.UI.createLabel({
     text:'I am Window 1',
     win:win1
});
win1.add(label1);

var win2 = Titanium.UI.createWindow({  
     title:'Tab 2',
     backgroundColor:'#fff'
});
var tab2 = Titanium.UI.createTab({  
     title:'Tab 2',
     window:win2
});

var label2 = Titanium.UI.createLabel({
     text:'I am Window 2',
});
win2.add(label2);


tabGroup.addTab(tab1);  
tabGroup.addTab(tab2);  



main_win.open();

var button1 = Titanium.UI.createButton({
     title:"hello"
});
main_win.add(button1);
var button2 = Titanium.UI.createButton({
     title:"hello"
});
win1.add(button2);

button1.addEventListener('click', function(e) {
     tabGroup.open();
});

button2.addEventListener('click', function(e) {
     main_win.show();
     tabGroup.close();
});

现在 button2 没有按预期方式工作.我想切换回 window_1,即主窗口.代码出了什么问题.

Now button2 is not working in the desired way. I want to switch back to window_1 i.e the main window. What is going wrong with the code.

编辑

我想要一个窗口(可以是视图/窗口或其他东西.)即 ma​​in_win,它有一个名为 button1 的按钮.当我点击 button1 时,它会移动到另一个视图,该视图向我显示了与 tab1 关联的两个选项卡式视图,即 win1win2> 和 tab2.点击tab1将显示win1,点击tab2将显示win2.win1win2 都有一个按钮,上面写着 button2,点击它会将我们返回到 ma​​in_win.此外,我希望过渡就像我们默认从滚动视图中获得的一样.

I want to have a window (Can be a view/window or something else.) namely main_win which has a button named button1. When I click on button1 it moves to another view which shows me two tabbed views namely win1 and win2 associated with tab1 and tab2. Clicking on tab1 will show win1 and clicking on tab2 will show win2. Both win1 and win2 have a button say button2 clicking on which would send us back to the main_win. Also I want the transition to be like we are getting from scrollview by default.

推荐答案

我总是把 tabGroups 看作是窗口.它没有记录在案,但您可以在 Android 中的 tabGroups 上使用 exitOnClose 属性.请查看以下代码是否满足您的需求.针对 Android 2.2 的 Titanium SDK 1.7.5

I always just think about tabGroups as windows. It isn't documented, but you can use the exitOnClose property on tabGroups in Android. Please see if the following code does what you need. Titanium SDK 1.7.5 targeting Android 2.2

var main_win = Titanium.UI.createWindow({
    title : 'main_win',
    backgroundColor : '#fff'
});
var button1 = Titanium.UI.createButton({
    title : "open tabGroup",
    height:35,
    width:120
});
button1.addEventListener('click', function(e) {
    tabGroup.open();
});
main_win.add(button1);

var win1 = Titanium.UI.createWindow({
    title : 'Tab 1',
    backgroundColor : '#fff'
});
var tab1 = Titanium.UI.createTab({
    title : 'Tab 1',
    window : win1
});
var label1 = Titanium.UI.createLabel({
    text : 'I am Window 1',
    win : win1
});
win1.add(label1);
var button2 = Titanium.UI.createButton({
    title : "< back",
    top:5,
    left:5,
    height: 35,
    width: 80
});
win1.add(button2);
button2.addEventListener('click', function(e) {
    tabGroup.close();
});

var win2 = Titanium.UI.createWindow({
    title : 'Tab 2',
    backgroundColor : '#fff'
});
var tab2 = Titanium.UI.createTab({
    title : 'Tab 2',
    window : win2
});
var label2 = Titanium.UI.createLabel({
    text : 'I am Window 2',
});
win2.add(label2);
var button3 = Titanium.UI.createButton({
    title : "< back",
    top:5,
    left:5,
    height: 35,
    width: 80
});
win2.add(button3);
button3.addEventListener('click', function(e) {
    tabGroup.close();
});

var tabGroup = Titanium.UI.createTabGroup({
    exitOnClose: false
});
tabGroup.addTab(tab1);
tabGroup.addTab(tab2);

main_win.open();

这篇关于如何像滚动视图一样获得 windows 元素的过渡?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆