如果有人知道的例子在那里的,或I类可以添加到我的应用程序,将执行像VBox中,但有2个或多个列只是想知道?

我从一个循环将项目添加到一个垂直框,并且工作正常,但我想把它分成两列:

 _________________
|        |        |
| Item 1 | Item 2 |
| Item 3 | Item 4 |
| Item 5 |        |
|________|________|

现在我只是要通过侧并分配奇品2纵向方框边设置为一个,甚至给对方,但它会是不错的一个控制自动执行此操作。

修改结果 请停止给我变通。我身边已经有了一个功能性的工作。但是,如果你已经写了一个类,这样做,或者知道我在哪里可以在网上,我真的很感激它找到一个。 感谢

有帮助吗?

解决方案

flexlib( http://code.google.com/p/flexlib/ )有一个可爱的FlowContainer容器控件,将做正是你需要的。

其他提示

把它们在与HBox?

您可以使用含有与HBox于各行的垂直框和简单地填充每个HBox中与2项,是这样的:

变种VB:垂直框;结果 VAR array_of_items:阵列;

有(VAR我:= 0;我 {点击   VAR HB:HBOX =新HBox中();结果   hb.addChild(array_of_items [I]);结果   hb.addChild(array_of_items [I + 1]);结果   vb.addChild(HB);结果 }结果

我没有与此类似用HBox中和2种形式,其线的事情了很好。 动态地,可以交替添加子给每个窗体。

为什么不直接使用Tile容器和方向属性设置为您所需的流动方向?

我也有类似的问题我自己。这是我最后使用:

package {
    import mx.containers.HBox;
    import mx.containers.VBox;
    import mx.events.FlexEvent;

    public class MultiColumnVBox extends HBox {
        // public properties
        public var columnWidth:int;
        public var verticalGap:int;
        public var adjustForScrollbar:Boolean;

        public function MultiColumnVBox() {
            super();
            this.addEventListener(FlexEvent.CREATION_COMPLETE, rearrangeChildren);
        }

        private function rearrangeChildren(evtObj:FlexEvent):void {
            // height will change whilst rearranging children, as will the Children Array
            // we store them once at the start
            var myHeight:int = this.height;
            var children:Array = this.getChildren();

            var lastIndex:int = 0;
            var vBoxIndex:int = 0;
            var vBox:VBox;
            var totalHeight:int = -this.verticalGap + (this.adjustForScrollbar ? 16 : 0);

            for(var i:int=0; i<children.length; i++) {
                // resize each child and measure the height
                // if you don't want it resized to the columnWidth, set the maxWidth property
                children[i].width = this.columnWidth;
                children[i].validateSize();
                totalHeight += children[i].measuredHeight + this.verticalGap;
                // if we're too tall, or we've reached the last element, move them into a VBox
                if(totalHeight > myHeight || i == children.length-1) {
                    vBox = new VBox();
                    vBox.setStyle("verticalGap", this.verticalGap);
                    vBox.width = this.columnWidth;
                    // include last child if there is room
                    for(var j:int=lastIndex; j<(totalHeight > myHeight ? i : i+1); j++) {
                        vBox.addChild(children[j]);
                    }
                    this.addChildAt(vBox, vBoxIndex);
                    vBoxIndex += 1;
                    lastIndex = i;
                    totalHeight = -this.verticalGap + (this.adjustForScrollbar ? 16 : 0);
                }
            }
        }
    }
}

最终的结果是稍有不同,但是。而不是移动儿童交替列的,它填充的第一列,则第二,高度则第三等下去。

如果你打算使你的我们班,如你所说,类似的做法应该工作:等待CREATION_COMPLETE事件,然后重新安排孩子们分成两个垂直框控件

我认为Tile容器与方向=“水平”将做到这一点

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top