我如何在我的scrollView中添加View Array(在Android支持中)?

时间:2012-02-14 12:53:08

标签: titanium titanium-mobile titanium-modules

我是Titanium的新App Developer。我想创建一个窗口基础应用程序。谁在iphone或ipad或android平台上运行。 当我在iphone上运行应用程序而不是正常运行时,但是当我在Android上运行而不是显示msg(意外错误)时,它就会关闭。

var win1 = Titanium.UI.createWindow({   
   backgroundColor : '#f0f0f0',      
}); 

var view1 = Titanium.UI.createView({    
height  : 100,  
width   : 100,  
backgroundColor : '#ff0000',
borderColor  : '#000',

}); 

var scrollView1 = Titanium.UI.createScrollView({    
contentHeight   : 150,  
backgroundColor : '#00ff00',

});

var abc = new Array();

abc[0] = 'images/img.png',

abc[1] = 'images/img1.png',

scrollView1.add(abc); 

view1.add(scrollView1); 

win1.add(view1);

win1.open();

我如何在滚动视图中添加数组。 在数组i存储(图像路径)

请帮助我,

提前致谢,

4 个答案:

答案 0 :(得分:0)

试试这段代码:

var win1 = Titanium.UI.createWindow({   
   backgroundColor : '#f0f0f0'      
}); 

var view1 = Titanium.UI.createView({    
height  : 100,  
width   : 100,  
backgroundColor : '#ff0000',
borderColor  : '#000'

}); 

var scrollView1 = Titanium.UI.createScrollView({    
contentHeight   : 150,  
backgroundColor : '#00ff00'

});

var abc = ['images/img.png','images/img1.png'];

scrollView1.add(abc); 

view1.add(scrollView1); 

win1.add(view1);

win1.open();

答案 1 :(得分:0)

你不能将一个数组“添加”到一个窗口对象 - 'add'只接受Titanium Proxy对象 - 从Ti.UI.create ....方法返回的东西 - 作为参数。请参阅下面的评论代码:

var win1 = Titanium.UI.createWindow({   
  backgroundColor : '#f0f0f0',      
}); 

var view1 = Titanium.UI.createView({    
  height  : 100,  
  width   : 100,  
  backgroundColor : '#ff0000',
  borderColor  : '#000',
}); 

var scrollView1 = Titanium.UI.createScrollView({    
  contentHeight   : 150,  
  backgroundColor : '#00ff00',
});

var abc = ['images/img.png', 'images/img1.png'];

// if you want the image paths available as a variable, just set it
scrollView1.abc = abc;
// But I don't understand why you are doing this - you can just access the paths
// from abc directly 

view1.add(scrollView1); 

// You were adding the scroll view twice: win1.add(scrollView1);
// You want to add the view:
win1.add(view1);

win1.open();

答案 2 :(得分:0)

试试这个,

var array = new Array();
array[0] = 'image path';
array[1] = 'image path';

for(a = 0; a<array.length;a++){
var lab1            = Titanium.UI.createLabel({
   backgroundImage      : array1[a],
   height           : 75,
   width            : 75,
   backgroundColor          : '#712347',
   borderRadius         : '10',
   zIndex           : 11,
   });

scrLabel.add(lab1);
}

我认为这是支持你的。

答案 3 :(得分:0)

var array = new Array();
array[0] = 'image path';
array[1] = 'image path';

for(a = 0; a<array.length;a++){
var lab1            = Titanium.UI.createImageView({
   backgroundImage      : array1[a],
   height           : 75,
   width            : 75,
   backgroundColor          : '#712347',
   borderRadius         : '10',
   zIndex           : 11,
   });

scrLabel.add(lab1);
}
相关问题