如何像滚动视图一样获得窗口元素的转换?

发布于 2024-12-20 20:09:15 字数 1751 浏览 4 评论 0原文

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

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 即主窗口。代码出了什么问题。

编辑

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

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

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.

EDIT

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

笑梦风尘 2024-12-27 20:09:15

我总是将 tabGroup 视为窗口。它没有记录,但您可以在 Android 中的 tabGroups 上使用 exitOnClose 属性。请看看下面的代码是否满足您的需要。针对 Android 2.2 的 Titanium SDK 1.7.5

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

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();
高速公鹿 2024-12-27 20:09:15

tabgroup 是一个全局元素。我不确定是否可以关闭它 - 显然不能。 如果您必须隐藏它,您可以跳转到

tabGroup.setActiveTab(id_of_your_tab);

需要构建自己的栏的选项卡。

此外,是否可以为视图或滚动视图制作选项卡式视图。

您可以在窗口上使用 scrollview

var scrollView = Titanium.UI.createScrollView({
    contentWidth:'auto',
    contentHeight:'auto',
    top:0,
    showVerticalScrollIndicator:true,
    showHorizontalScrollIndicator:true
});
var view = Ti.UI.createView({
    backgroundColor:'#336699',
    borderRadius:10,
    width:300,
    height:2000,
    top:10
});
scrollView.add(view);
Titanium.UI.currentWindow.add(scrollView);

tableviews 也是实现可滚动视图的常用方法。

在为 Android 制作应用程序时我还可以使用哪些其他选项
设备。

查看 titanium api。它显示 Android 上可用的方法和视图。您还应该了解 Android 设备的多密度。因此您需要提供多种分辨率的图像。请查看钛金指南

希望有帮助

the tabgroup is a global element. i'm not sure if it is possible to close it - apparently not. you can jump to a tab with

tabGroup.setActiveTab(id_of_your_tab);

you need to build your own bar if you have to hide it.

Also, is it possible to make a tabbed-view for views or scroll-views.

you can use a scrollview on your window:

var scrollView = Titanium.UI.createScrollView({
    contentWidth:'auto',
    contentHeight:'auto',
    top:0,
    showVerticalScrollIndicator:true,
    showHorizontalScrollIndicator:true
});
var view = Ti.UI.createView({
    backgroundColor:'#336699',
    borderRadius:10,
    width:300,
    height:2000,
    top:10
});
scrollView.add(view);
Titanium.UI.currentWindow.add(scrollView);

tableviews are also a common way to implement a scrollable view.

What other options can I use while making the App for an android
device.

have a look at the titanium api. it displays which methods and views are available on android. you should also be aware of the multi density for android devices. so you need to provide youre images in multiple resolutions. have a look at the titanium guidelines.

hope it helps

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文