Skip to content

Instantly share code, notes, and snippets.

@pec1985
Created August 22, 2011 21:31
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pec1985/1163654 to your computer and use it in GitHub Desktop.
Save pec1985/1163654 to your computer and use it in GitHub Desktop.
Simple grid that supports orientation change
var win = Ti.UI.createWindow({
orientationModes:[1,2,3,4]
});
var scrollView = Ti.UI.createScrollView({
top:0,
bottom:0,
right:-1,
left:-1,
backgroundColor:'blue',
contentHeight:'auto',
layout:'horizontal'
});
function square(i){
var view = Ti.UI.createView({
backgroundColor:'green',
width:94,
height:94,
top:10,
left:10,
id:i
});
view.addEventListener('click', function(){
alert(view.id);
});
Ti.Gesture.addEventListener('orientationchange', function(e){
if(e.orientation == 3 || e.orientation == 4){
view.backgroundColor = 'red';
view.width = 108;
view.height = 108;
} else {
view.backgroundColor = 'green';
view.width = 94;
view.height = 94;
}
});
return view;
}
for(var i=0;i<100;i++){
scrollView.add(
square(i)
);
}
win.add(scrollView);
win.open();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment