apache-flex - Flex 4 动态调整父容器的大小以包含子容器

标签 apache-flex mxml flex4

有没有一种简单的方法可以让父容器(例如 Group)在其子容器调整大小时调整大小?

下面是一个小示例应用程序。当我将 200x200 的“食物”放入“胃”时,胃及其包含 100x100 的“ body ”应该调整大小以容纳食物。

有什么想法吗?

(来自这个要点 http://gist.github.com/301292 )

<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
      xmlns:s="library://ns.adobe.com/flex/spark"
      xmlns:mx="library://ns.adobe.com/flex/halo"
      minWidth="1024"
      minHeight="768"
      creationComplete="application1_creationCompleteHandler(event)">
 <fx:Script>
  <![CDATA[
   import mx.events.FlexEvent;

   protected function application1_creationCompleteHandler(event:FlexEvent):void {

   }

   protected function eatFoodTrigger_clickHandler(event:MouseEvent):void {
    var food:Border = new Border();
    food.setStyle('backgroundColor', 0x15DCA9);
    food.width = 200;
    food.height = 200;

    stomach.addElement(food);

   }
  ]]>
 </fx:Script>

 <s:Group verticalCenter="0" horizontalCenter="0">
  <s:layout>
   <s:VerticalLayout horizontalAlign="center" />
  </s:layout>

  <s:Label fontSize="24" text="The 100x100 pink/brown body has a stomach inside it.
     Press eat and the stomach gets 200x200 'food' added to it.
     I want the body and the stomach to expand to fit the food." width="200">
  </s:Label>

  <s:Border id="body"
      backgroundColor="0x333333"
      minWidth="100"
      minHeight="100"
      borderColor="0xFF4466"
      borderWeight="5">
   <s:Group id="stomach">
   </s:Group>
  </s:Border>

  <s:Button id="eatFoodTrigger" click="eatFoodTrigger_clickHandler(event)" label="eat" />
 </s:Group>
</s:Application>

最佳答案

好的,这是 flex 4 sdk 中的一个错误,现在已修复。太棒了。

发件人:http://forums.adobe.com/thread/575252

Your example works for me in a recent build. Perhaps it was a bug in an old build. Try one of the new nightly builds:

http://opensource.adobe.com/wiki/display/flexsdk/DownloadFlex4

-Ryan

关于apache-flex - Flex 4 动态调整父容器的大小以包含子容器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2248672/

相关文章:

ios - OneSignal 上的关键警报支持不起作用

apache-flex - 为什么我不能限制 NumericStepper 包含负号?

ios - 使用自定义 URL 方案将 PDF url 发送到使用 as3 和 FlashBuilder 4.6 的 iBooks 应用程序?

apache-flex - 柔性 4 : parent and owner property of UIComponent

flex4 - 滚动 Spark ItemRenderer 会将 View 状态切换为默认状态!

apache-flex - 无法解析 <s :Sequence> to a component implementation after adding AIR 3. 6

xml - 基于 XML 或数据库结构的 Flex 代码生成器

正则表达式验证器 MXML

apache-flex - ActionScript 中组件不同部分的不同工具提示

apache-flex - 在 Flex 4 列表中处理鼠标单击以查找所选项目(因为 itemClick 消失了)