I have a custom HBox as so....
我有一个定制的HBox ......
public class MyBar extends HBox {
公共类MyBar扩展HBox {
public function MyBar() {
super();
this.height = 65;
this.percentWidth = 100;
var newButton:Button = new Button();
//.....
newButton.y = 20;
var spacer1:Spacer = new Spacer();
spacer1.percentWidth = 50;
var spacer2:Spacer = new Spacer();
spacer2.percentWidth = 50;
this.addChild(spacer1);
this.addChild(newButton);
this.addChild(spacer2);
}
}
This displays a button in the center of the HBox, but the button is aligned to the top of the Box, I would like it to be in the center.
这会在HBox的*显示一个按钮,但是按钮与Box的顶部对齐,我希望它位于中心。
I'm sure I've had this working before as simply as setting the y value. But doesn't seem to be working now. I am using SDK 3.3
我确信我之前有这个工作就像设置y值一样简单。但现在似乎没有工作。我正在使用SDK 3.3
Anyone have any clues as to why I'm having difficulty with this?
任何人都有任何线索,为什么我有这个困难?
Thanks!
1 个解决方案
#1
Setting the y won't work as the HBox controls the y positions. If you'd like all the buttons to be placed in the middle of the HBox you need to set verticalAlign to middle
设置y将不起作用,因为HBox控制y位置。如果您希望将所有按钮放在HBox的中间,则需要将verticalAlign设置为中间
in code that would be
在代码中
setStyle("verticalAlign", "middle");
#1
Setting the y won't work as the HBox controls the y positions. If you'd like all the buttons to be placed in the middle of the HBox you need to set verticalAlign to middle
设置y将不起作用,因为HBox控制y位置。如果您希望将所有按钮放在HBox的中间,则需要将verticalAlign设置为中间
in code that would be
在代码中
setStyle("verticalAlign", "middle");