Skip to content

Instantly share code, notes, and snippets.

@pec1985
Created October 23, 2011 05:30
Show Gist options
  • Save pec1985/1306917 to your computer and use it in GitHub Desktop.
Save pec1985/1306917 to your computer and use it in GitHub Desktop.
Android quick dashboard view
var win = Ti.UI.createWindow({});
win.open();
var height = Ti.Platform.displayCaps.platformHeight-40;
var width = Ti.Platform.displayCaps.platformWidth;
var viewsArray = [];
function myView(a){
var v = Ti.UI.createView({
backgroundColor:"#"+((1<<24)*Math.random()|0).toString(16)
});
v.add(Ti.UI.createLabel({text:a,textAlign:'center'}));
return v;
}
var i = 42;
var x = 0;
while(i--){
viewsArray.push(myView(x++));
}
var scrollableView = Ti.UI.createScrollableView({
top:0,
right:0,
left:0,
bottom:0,
backgroundColor:'black'
});
function mainView(){
var v = Ti.UI.createView({
layout:'horizontal',
width:width,
height:height,
top:0
});
return v;
}
win.add(scrollableView);
function createDashboardView(){
var mainViews = [];
var len = viewsArray.length;
var x = 0;
var meh = mainView();
for(var i = 0; i < len; i++){
var view = viewsArray[i];
view.top = 0;
view.left = 0;
view.width = meh.width/3;
view.height = meh.height/3;
meh.add(view);
if(x == 9){
mainViews.push(meh);
meh = null;
meh = mainView();
x = 0;
}
x++;
}
mainViews.push(meh);
scrollableView.views = mainViews;
var time = new Date().getTime();
var f = [];
for(var i = 0; i < 1000; i++){
f.push(i);
}
alert(new Date().getTime() - time);
}
createDashboardView();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment