1


是否可以ScrollView在钛合金中添加多个视图?所以可以说我有以下内容:

var scrollView = Titanium.UI.createScrollView();
var views = [];

var view1 = Titanium.UI.createView();
views.push(view1);

var view2 = Titanium.UI.createView();
views.push(view2);

scrollView.add(views);

window.add(scrollView);

上面的方法有用吗?如果不是,需要做什么才能使其工作?

4

2 回答 2

0

根据他们的文档,这应该行不通。(以前从未尝试过。)但你可以这样做:

views.forEach(function(view) {
  scrollView.add(view);
});
于 2013-04-07T09:31:36.160 回答
0

我知道这有点晚了,但它是我用来解决这个问题的解决方案,希望它仍然有用。基本上,它涉及将滚动视图的不透明度设置为 0,直到您完成加载。这意味着,它们不是一次出现 1 行,而是同时出现,并且可以在您的程序/用户执行其他操作时在后台运行。请注意,它仅在 scrollView 为空时才有效 - 对于向其中已有内容的 scrollView 添加行不是一个好的解决方案:

var sView = Titanium.UI.createScrollView({
    //Whatever properties you need for your scrollView
    opacity: 0,
});

//childViews is an array of all the stuff you'd like to add to sView
childCount = childViews.length

//Add a postlayout event to the last childView - this will automatically set the opacity to 1 when the last child is loaded
childViews[childCount - 1].addEventListener('postlayout', function showScrollView(e){
    this.parent.setOpacity(1);
    this.removeEventListener(showScrollView);
});

//Iteratively add each view in the array to the sView
for (var x = 0; x < childCount; x++) {
   sView.add(childViews[x]);
}
window.add(sView);
于 2013-05-11T01:46:36.320 回答