Skip to content

Instantly share code, notes, and snippets.

@mauropm
Created July 4, 2013 05:40
Show Gist options
  • Save mauropm/5925157 to your computer and use it in GitHub Desktop.
Save mauropm/5925157 to your computer and use it in GitHub Desktop.
Vertical automatic scrollableview. This will automatically add views in the end and remove views from the beginning of the views array. USE: Create a new mobile project in Ti Studio (classic titanium) and paste this to app.js. With some code from Dawson: https://gist.github.com/dawsontoth/839218 (to do the vertical part)
var win = Ti.UI.createWindow({
backgroundColor:'white',
});
// *** This is taken from Dawsontoth's https://gist.github.com/dawsontoth/839218
var rotate = Ti.UI.create2DMatrix().rotate(90);
var counterRotate = rotate.rotate(-180);
// *** end of the code taken from Dawsontoth's
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,
weight: Ti.UI.FILL,
transform:counterRotate,
});
}
var autoscroll = Ti.UI.createScrollableView({
showPagingControl:false,
height: 320,
width: 480,
transform:rotate,
});
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