开发者

How do I create a VBox that will grow to fit all the children rather than use a scrollbar?

开发者 https://www.devze.com 2022-12-20 09:50 出处:网络
I have a Canvas with a VBox in it. As I add items to the VBox, I want the VB开发者_运维技巧ox to grow, I want the scrollbar on the Canvas to control the visibility.

I have a Canvas with a VBox in it. As I add items to the VBox, I want the VB开发者_运维技巧ox to grow, I want the scrollbar on the Canvas to control the visibility.

How do I accomplish this?


try setting the VBoxes verticalScrollPolicy to off (false? not sure, whatever the negative option is)


Credit to invertedSpear as it was a correct answer, but here's an example that demonstrates it:

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical">

<mx:Script>
    <![CDATA[
        import mx.controls.Label;

        private function createChild() : DisplayObject {

            var label:Label = new Label();
            label.text = "hello " + container.numChildren;
            return label;

        }

    ]]>
</mx:Script>


<mx:Button label="Add More" click="container.addChild(createChild())" />

<mx:Canvas width="100%" height="100%" backgroundColor="#FF0000">

    <mx:VBox id="container" verticalScrollPolicy="off" backgroundColor="#FFF" backgroundAlpha="0.5">

        <mx:Label text="hello" />

    </mx:VBox>

</mx:Canvas>

</mx:Application>
0

精彩评论

暂无评论...
验证码 换一张
取 消