Skip to content

Instantly share code, notes, and snippets.

@simryang
Created June 29, 2012 11:00
Show Gist options
  • Save simryang/3017358 to your computer and use it in GitHub Desktop.
Save simryang/3017358 to your computer and use it in GitHub Desktop.
scrollableview with remote images for Titanium Appcelerator
var win = Ti.currentWindow;
var imageCollection = [
'http://example.com/images/1.jpg',
'http://example.com/images/2.jpg',
'http://example.com/images/3.jpg',
'http://example.com/images/4.jpg',
'http://example.com/images/5.jpg',
'http://example.com/images/6.jpg'
];
var scrollGallery = Ti.UI.createScrollableView({
showPagingControl:false,
maxZoomScale:5,
minZoomScale:1
});
var viewCollection = [];
for (var i = 0; i < imageCollection.length; i++) {
var view = Ti.UI.createView({});
var img = Ti.UI.createImageView({
maxZoomScale:5,
defaultImage:'images/default_image.png'
});
if (i < 3) { // only preload the first 3 images
img.image = imageCollection[i];
}
view.add(img);
viewCollection.push(view);
}
scrollGallery.addEventListener('scroll', function(e){
if (scrollGallery.currentPage < (imageCollection.length-1)) {
var nxt = scrollGallery.currentPage+2; // get the 2nd next image (since the next one is already loaded)
scrollGallery.views[nxt].children[0].image = imageCollection[nxt];
}
});
scrollGallery.views = viewCollection;
win.add(scrollGallery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment