【问题标题】:How do I change the size of an HBox in Flex to fit its container?如何在 Flex 中更改 HBox 的大小以适应其容器?
【发布时间】:2010-07-28 21:14:32
【问题描述】:

我创建了一个 HBox,用按钮网格填充它,并设置滚动策略。当我调整窗口大小时,舞台会改变大小,HBox 也会改变......到一个点。一旦它达到它所包含的 Grid 的高度,它就会停止收缩,就像它有一个“最小高度”一样。这会破坏我在这种情况下尝试建立的滚动条。

我已经将高度设置为 100%,它不应该总是取舞台的高度,它的父级吗?

<?xml version="1.0" encoding="utf-8"?> 
<mx:Application 
xmlns:mx="http://www.adobe.com/2006/mxml"
initialize="init();" horizontalScrollPolicy="off" verticalScrollPolicy="off" width="100%"> 

<mx:Script>
    <![CDATA[
        import mx.controls.Button;
        import mx.containers.Grid;
        import mx.containers.GridRow;
        import mx.containers.GridItem;

        protected function init():void {    
            for (var i:int = 0; i < 3; i++) {
                var gRow:GridRow = new GridRow();
                gRow.percentWidth = 100;
                gRow.height = 100;
                var gItem:GridItem = new GridItem();
                gItem.percentWidth = 100;
                var btn:Button = new Button();
                btn.label = "BUTTON";
                btn.percentWidth = 100;
                btn.percentHeight = 100;
                gItem.addChild(btn);
                gRow.addChild(gItem);
                mainGrid.addChild(gRow);
            }       
        }         
  ]]>
</mx:Script>

<mx:HBox width="100%" height="100%" horizontalScrollPolicy="off" verticalScrollPolicy="on" id="main" clipContent = "true">
    <mx:Grid id="mainGrid" width="100%" height="100%" />
</mx:HBox>
</mx:Application>

【问题讨论】:

    标签: apache-flex actionscript-3 button mxml hbox


    【解决方案1】:

    所以看起来我设法在我的问题中提到了最终的答案。这是"minHeight" 属性的人,看起来它被设置为包含的网格高度,并且不会缩小。将其设置为 0,一切顺利。

    我希望我与自己的这个对话可以帮助别人其他。 :)

    【讨论】:

    • +1 您已经回答了自己的问题。再投两票,您将获得自学徽章:)
    【解决方案2】:

    你可以尝试给它 HBox 的高度,如 height="{hb.height}" ,hb as id

    【讨论】:

    • 我当然可以设置 HBox 来反映舞台的高度,但我使用 Flex 的全部原因是因为布局管理器应该处理这个问题。我觉得我只是在某个地方错过了一个设置。
    猜你喜欢
    • 1970-01-01
    • 2015-12-21
    • 2017-12-10
    • 2015-04-07
    • 2021-05-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-02-09
    相关资源
    最近更新 更多