我无法将 VBox 中的组件居中。我想设置标准 css 元素“align: center”。我怎样才能在 Flex 中做到这一点?
<mx:VBox>
<mx:LinkButton label="Tag1" />
<mx:Image source="@Embed(source='../icons/userIcon.png')" />
<mx:Label id="username" text="Nickname" visible="false" fontWeight="bold" />
</mx:VBox>
谢谢
最佳答案
简单地说,你可以这样做:
<mx:VBox width="200" horizontalAlign="center">
<mx:Label text="foo" />
</mx:VBox>
我刚刚尝试了这个例子,效果很好。如果容器的宽度由其子容器决定,则它可能不会正确对齐:
<mx:VBox horizontalAlign="center" borderStyle="solid">
<mx:Label text="foo" />
<mx:Label text="bar" />
</mx:VBox>
但是,进一步指定宽度显示此属性可以正常工作:
<mx:VBox width="200" horizontalAlign="center" borderStyle="solid">
<mx:Label text="foo" />
<mx:Label text="bar" />
</mx:VBox>
关于apache-flex - 柔性,HBox : how to horizontally center all children?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2663428/