titanium开发教程-02-11增加交互性,在任何view

1

 

var win = Titanium.UI.createWindow({
	title:"Adding Interactivity to Any View",
	backgroundColor:"#FFFFFF",
	exitOnClose:true
})

var view = Titanium.UI.createView({
	top:0,
	left:0,
	height:54,
	width:"100%",
	backgroundColor:"#EEEEEE",
	id:"View"
})

var image = Titanium.UI.createImageView({
	image:"images/taste-cal.png",
	top:0,
	left:0,
	height:54,
	width:36,
	id:"Image"
})

var label = Titanium.UI.createLabel({
	text:"Taste of California",
	top:0,
	left:42,
	height:54,
	width:200,
	color:"#000000",
	backgroundColor:"orange",
	id:"Label"
})

var results = Titanium.UI.createLabel({
	text:"Touch the image, label, or view above",
	bottom: 24,
	height:"auto",
	width:"auto",
	textAlign:"center"
})

function touchHandler(e){	
	results.text = e.source.id + " was tapped";
}

function touchMoveHandler(e){
	if(e.y > 54){
		results.text = "Touch move on window \nx:" + e.x + ", y:" + e.y
	}
}

image.addEventListener("touchend", touchHandler);
label.addEventListener("touchend", touchHandler);
view.addEventListener("touchend", touchHandler);
win.addEventListener("touchmove", touchMoveHandler);

view.add(image);
view.add(label);

win.add(view);
win.add(results);

win.open();
posted @ 2012-03-17 01:09  校长阿四  阅读(538)  评论(0编辑  收藏  举报