Button
Hi
Would someone kindly explain to me how to use the center property for buttons?
It's really not clear from the API, which states:
center (object) - a dictionary with properties x and y to indicate the center of the views position relative to the parent view
Thank you in advance
3 Answers
-
Accepted Answer
Using the "top" and "left" properties combined on the button MIGHT have the same effect as using "center".
If you add elements (like buttons) to a window that's not yet open, all elements will be aligned to the left of the screen while it transitions into the new window when you open() it, and then they will centralize themselves once the new window is fully open.
This causes a weird behavior because the buttons will immediately jump from the left side to the center of the screen on the new window.
By using the center property on these elements you can tell the app where they should be centered instead of relying on the future window to position them later.
Relying on the parent window to center (assuming an iphone in portrait mode):
var b1 = Titanium.UI.createButton({ height:40, width:200, top:10, });
Centering it yourself (it might not show up at the same place depending on your parent elements):
var b1 = Titanium.UI.createButton({ height:40, width:200, center:{x:160,y:10}, });
You might wanna add a button to a window that is not yet open because sometimes when you open a window and then add a button it might take some time for the button to get drawn.
-
I think the term 'dictionary' means the standard format where parameters are enclosed in curly brackets. If I am right, a 'dictionary with properties x and y' would be
something like createButtton({center:x=0.5,y=0.5}) but happily things seem default to the center of views anyway, at least horizontally.regards,
JH
-
I'm not in a position to test this code right now, but you might try:
center:{x:0.3,y:0.6},