Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Adobe AIR Development

Reply
Developer
ectar
Posts: 107
Registered: ‎11-20-2009
My Device: Tegra 2 Android tablet and Playbook
My Carrier: Rogers
Accepted Solution

How to horizontally and vertially center center 3 horizontally aligned buttons?

[ Edited ]

Can not wrap up my brain around simple centering problem... I guess that becasue it is friday!? :smileyhappy:

 

Lets say I have to position 3 Buttons side by side in variable width container, and I want them to be always centered in that container vertically and horizontally. How to acheiwe that with Container?

 

And we a talking about QNX components only, and 3 bunnons mean [2:n] bumber of buttons

http://riahut.com
Please use plain text.
Developer
ajerman
Posts: 101
Registered: ‎03-18-2011
My Device: Playbook Simulator
My Carrier: AT&T

Re: How to horizontally and vertially center center 3 horizontally aligned buttons?

[ Edited ]

I'd use an HGroup with verticalAlign and horizontalAlign set to middle and center. Should work for what you're asking for I believe.

Please use plain text.
Developer
jffurlan
Posts: 1,003
Registered: ‎01-16-2011
My Device: PlayBook (sim)
My Carrier: Rogers

Re: How to horizontally and vertially center center 3 horizontally aligned buttons?

[ Edited ]

assume container name is container. and button name is button

 

 

button.setPosition = ((container.width - button.width/2), (container.height - button.height/2));

 

I might be a little rusty but that should do the trick.

 

EDIT: That will actually place it directly in the middle of the container. If you wanted it one to be 25% of the way in, and one 75%, you'd have to use the following

 

25%

 

button.setPosition = ((container.width - button.width/4), (container.height - button.height/4));

75% (the math on this might be wrong - maybe someone can chime in and help)

 

button.setPosition = ((container.width - button.width*.75), (container.height - button.height*.75));

 

- If you like my response/post, or it helped you find an answer you were looking for, please provide a Kudo - white star to the bottom right of this post. -
- Please use the search bar at the top, or check out the PlayBook FAQ's for help getting started -
- Hockey DrillBook -
Please use plain text.
Developer
ectar
Posts: 107
Registered: ‎11-20-2009
My Device: Tegra 2 Android tablet and Playbook
My Carrier: Rogers

Re: How to horizontally and vertially center center 3 horizontally aligned buttons?

That is easy, but in case n buttons wont work.

http://riahut.com
Please use plain text.
Developer
jffurlan
Posts: 1,003
Registered: ‎01-16-2011
My Device: PlayBook (sim)
My Carrier: Rogers

Re: How to horizontally and vertially center center 3 horizontally aligned buttons?

Edited my post to avoid layering all of them on top of each other.

- If you like my response/post, or it helped you find an answer you were looking for, please provide a Kudo - white star to the bottom right of this post. -
- Please use the search bar at the top, or check out the PlayBook FAQ's for help getting started -
- Hockey DrillBook -
Please use plain text.
Developer
ectar
Posts: 107
Registered: ‎11-20-2009
My Device: Tegra 2 Android tablet and Playbook
My Carrier: Rogers

Re: How to horizontally and vertically center center 3 horizontally aligned buttons?

[ Edited ]

Cup of coffee cleared my mind so here is solution and I'm sorry guys that I didn't think hard enough at the beginning and asked you  to think, but I believe this might be helpful to many other people:

 

Key thing here is SPACER, people never forget about Spacers... LOL

 

 

			var container:Container = new Container();

var bb1:LabelButton = new LabelButton();
bb1.label = "Knopka1"
bb1.width = 120;

var bb2:LabelButton = new LabelButton();
bb2.label = "Knopka2"
bb2.width = 120;

var bb3:LabelButton = new LabelButton();
bb3.label = "Knopka3"
bb3.width = 120;

container.margins = Vector.<Number>([10,10,10,10]);
container.width = 500;
container.height = 200;
container.debugColor = 0x0033FF;
container.flow = ContainerFlow.HORIZONTAL;
container.align = ContainerAlign.MID;
container.padding = 10;

var sp1:Spacer = new Spacer();
var sp2:Spacer = new Spacer();

container.addChild(sp1);
container.addChild(bb1);
container.addChild(bb2);
container.addChild(bb3);
container.addChild(sp2);
container.layout();

addChild(container);

Capture.PNG

http://riahut.com
Please use plain text.