钛添加多个视图到滚动视图一次




是否可以在钛中添加多个视图到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);

上述方法可行吗?如果不是,需要做些什么才能使其发挥作用?

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

views.forEach(function(view) {
  scrollView.add(view);
});

我知道这有点晚了,但这是我用来解决这个问题的解决方案,希望它仍然有帮助。基本上,它涉及到将scrollView的不透明度设置为0,直到完成加载。这意味着,而不是一次出现一行,他们都同时出现,这可以在后台运行,而您的程序/用户做其他事情。请注意,它只工作,如果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);

最新更新