apache-flex - Flex - 垂直放置水平 HBox 的子项

标签 apache-flex actionscript-3 alignment hbox

我有一个自定义的 HBox ......

公共(public)类 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

有人知道为什么我在这方面遇到困难吗?

谢谢!

最佳答案

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

在代码中会是

setStyle("verticalAlign", "middle");

关于apache-flex - Flex - 垂直放置水平 HBox 的子项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/756079/

相关文章:

css - 当我使用 css 将 div 对齐到页面的中心时,它从图像的左侧而不是中心开始

apache-flex - 当 popUpWidthMatchesAnchorWidth 为 FALSE 时,将下拉列表向右对齐

css - FLEX - 是否可以将默认的表单项标签字体粗细从粗体改成正常?

c++ 解决方案在 leetcode 上失败,地址未对齐错误,但在 Visual Studio 中运行

actionscript-3 - Starling MovieClip 帧不适合 2048。一个 MC 有多个 TextureAtlas?

actionscript-3 - Flash AS3 中的文本链接

ios - 如果另一个项目不存在,Xcode 将项目居中对齐

apache-flex - Actionscript 3 - 解析 yyyy-mm-dd hh :mm:ss to a Date object? 的最快方法

apache-flex - Actionscript flex : Converting # colors to uint

algorithm - AS3动态文本算法