Skip to content

Instantly share code, notes, and snippets.

@alanleard
Created November 29, 2011 19:58
Show Gist options
  • Save alanleard/1406199 to your computer and use it in GitHub Desktop.
Save alanleard/1406199 to your computer and use it in GitHub Desktop.
Dynamic Image Add to ScrollView
var win = Ti.UI.createWindow();
var scrollView = Ti.UI.createScrollView({
contentWidth:'auto',
contentHeight:'auto',
left:0, right:0,
top:200
});
var imageCount = 24;
var start = 1;
var images = Ti.UI.createView({layout:'horizontal'});
function addImages(a, b){
for (var i=a;i<b;i++)
{
if(i<imageCount)
{
var imageView = Ti.UI.createImageView({
height:75,
width:75,
image:'images/'+i+'.jpg',
left:5
});
images.add(imageView);
images.width+=80;
start = i;
} else {
start = 1;
}
}
};
addImages(start,8);
scrollView.add(images);
scrollView.addEventListener('scroll', function(e){
if(e.x>(images.width-Ti.Platform.displayCaps.platformWidth-10)){
addImages(start,start+8);
}
})
win.add(scrollView);
win.open();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment