Skip to content

Instantly share code, notes, and snippets.

@mauropm
Last active December 19, 2015 08:19
Show Gist options
  • Save mauropm/5925078 to your computer and use it in GitHub Desktop.
Save mauropm/5925078 to your computer and use it in GitHub Desktop.
This app.js will create a new scrollableview, then will be removing and adding views, it removes the beginning (HEAD) of the views array in the scrollableview and will add a new view at the end (TAIL). To use this, please add a new mobile project in Ti Studio (classic titanium) and then paste this code to app.js. If you do funny things with this…
var win = Ti.UI.createWindow({
backgroundColor:'white',
});
function randomInt(min, max) {
return Math.round(min + Math.random()*(max-min));
}
function getView(){
var rnd = randomInt(0,200) % 3;
var color = 'black';
switch(rnd){
case 0:
color='gray';
break;
case 1:
color='pink';
break;
case 2:
color='yellow';
break;
default:
color='black';
break;
}
return Ti.UI.createView({
backgroundColor:color,
top:0,
left:0,
height: Ti.UI.FILL,
width: Ti.UI.FILL,
});
}
var autoscroll = Ti.UI.createScrollableView({
showPagingControl:true,
top:0,
left:0,
height: Ti.UI.FILL,
width: Ti.UI.FILL,
});
for(i=0;i<10;i++){
autoscroll.addView(getView());
}
setInterval(function(){autoscroll.removeView(0); Ti.API.info("Removed head");},3000);
setInterval(function(){autoscroll.addView(getView()); Ti.API.info("Added view");},2500);
win.add(autoscroll);
win.open();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment