See attached video for comparison demo.
var win = Ti.UI.createWindow({
navBarHidden:true,
exitOnClose:true,
backgroundColor: '#fff'
});
var view = Ti.UI.createView({
// initial setting of of a small box view that is centered
width: 10,
height: 10,
center: {
x: Ti.Platform.displayCaps.platformWidth / 2,
y: Ti.Platform.displayCaps.platformHeight / 2
},
backgroundColor: '#f00'
});
var openBtn = Ti.UI.createButton({
left: 10,
right: 10,
height: 50,
title: 'Open'
});
openBtn.addEventListener('click', function(e) {
var closeBtn = Ti.UI.createButton({
left: 10,
right: 10,
height: 50,
title: 'Close'
});
closeBtn.addEventListener('click', function(e) {
view.remove(closeBtn);
view.animate({
center: {
x: Ti.Platform.displayCaps.platformWidth / 2,
y: Ti.Platform.displayCaps.platformHeight / 2
},
width: 10,
height: 10,
duration: 300
},
function(e) {
win.remove(view);
Ti.API.info('This is going to be called multiple times.');
});
});
win.add(view);
// animate small, centered box
view.animate({
center: {
x: Ti.Platform.displayCaps.platformWidth / 2,
y: Ti.Platform.displayCaps.platformHeight / 2
},
width: Ti.Platform.displayCaps.platformWidth,
height: Ti.Platform.displayCaps.platformHeight,
duration: 300
},
function(e) {
view.add(closeBtn);
Ti.API.info('This is going to be called multiple times.');
});
});
win.add(openBtn);
win.open();
the "center" property wasn't implemented before a few days ago. If you want a truly centered view shouldn't you be using center: { x: 0, y: 0 } ? Dividing platformHeight/platformWidth by two would be good for top and left, but not center x/y?
I suppose this has to do with expectation. Is the view centered relative to it's parent and where is the parent's coordinate origin?
In a layout tool, if the origin starts in the upper left (0,0), then the relative position of the element positioned on top would be width/2, height/2.
Originally, this worked on both iOS and Android (as seen in video) as relative to the parents origin at (0,0), upper-left.
Screenshot one: Where is it?
Screenshot two: How 0,0 works on iOS
Ahh.. I guess I was under the impression that "center" was relative to the parent's center position. This never actually "worked" in Android because the center property wasn't even implemented until a few days ago, so my guess is the values you had were incidental with some of our default behaviors :)
(from [eecab83e319ad70b79af913fbc3ad0d99f8265bc]) center positions are parent-relative to 0,0 instead of parent-center relative [#2774 state:fixed-in-qa]
https://github.com/appcelerator/titanium_mobile/commit/eecab83e319ad70b79af913fbc3ad0d99f8265bc"> https://github.com/appcelerator/titanium_mobile/commit/eecab83e319a...
sim 2.2, G1 (1.6) [INFO] Titanium SDK version: 1.5.2 (01/10/11 08:22 682e79e) and [INFO] Titanium SDK version: 1.6.0 (01/10/11 08:25 3452f06)