我正在寻找让 flex 4 图像对象在其父容器(基于组的自定义组件)调整大小时调整大小并水平居中的最佳方法。我无法设置 HorizontalCenter="0" 来完成图像居中,因为我使用移动过渡来将图像“滑入”和“滑出”视图。
我在组件中从外部设置图像源。这是我的组件代码的简化示例,它仅解决了调整图像大小的问题。
<s:Group xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/halo" >
<fx:Script>
<![CDATA[
public function assignImage(imgUrl:String):void
{
imgA.source = imgUrl;
imgA.visible = true;
}
override protected function updateDisplayList(w:Number,h:Number):void
{
imgA.width = w;
imgA.height = h;
super.updateDisplayList(w,h);
}
]]>
</fx:Script>
<s:Image id="imgA" visible="false" top="0" maintainAspectRatio="true" />
</s:Group>
非常感谢任何帮助——如果它更有意义,我也愿意接受另一种调整图像大小的方法。
提前致谢