titanium 入门 2 alloy v.s. Titanium SDK
访问量: 7651
很多时候,我们做页面布局,事件绑定,可以用alloy, 也可以用titanium SDK来实现,例如:
Titanium SDK Component |
Alloy Component |
Titanium.UI.* Objects Titanium.UI.createButton();
|
|
Titanium Object properties Titanium.UI.createButton({
text:
"Foobar"
,
top:
0
,
width: Ti.UI.SIZE
});
|
|
Titanium Object methods var button = Titanium.UI.createButton();
button.setTitle(
'Push Me!'
);
|
Use in the controller code. You need to define the id attribute of the object in the XML markup, so the object can be referenced in the controller. // Need to give the object an ID, for example, <Button id="button" />
$.button.setTitle(
'Push Me!'
);
|
Titanium Object events var button = Titanium.UI.createButton();
button.addEventListener(
'click'
, doClick);
|
XML attribute to bind a callback in the associated controller. Capitalize the first character of the event name and append 'on' to the beginning of the name. <!-- doClick needs to be declared in the associated controller -->
<Button onClick=
"doClick"
/>
|