2

我有一个自定义的 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);

}

}

这会在 HBox 的中心显示一个按钮,但该按钮与 Box 的顶部对齐,我希望它位于中心。

我确信我之前已经像设置 y 值一样简单地进行过这项工作。但现在似乎没有工作。我正在使用 SDK 3.3

任何人都知道为什么我在这方面遇到困难?

谢谢!

4

1 回答 1

11

设置 y 不起作用,因为 HBox 控制 y 位置。如果您希望将所有按钮放置在 HBox 的中间,则需要将 verticalAlign 设置为 middle

在代码中

setStyle("verticalAlign", "middle");
于 2009-04-16T13:29:43.933 回答