1

只是想知道是否有人知道那里的示例,或者我可以添加到我的应用程序中的类,该类可以像 VBox 一样执行但具有 2 列或更多列?

我正在从循环向 VBox 添加项目,效果很好,但我希望将其分成两列:

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

现在我只是要并排设置 2 个 VBox 并将奇数项分配给一个,甚至分配给另一个,但最好有一个控件自动执行此操作。

编辑
请停止给我解决方法。我已经有一个功能性的工作。但是,如果您已经编写了一个这样做的课程,或者知道我在哪里可以找到在线课程,我将不胜感激。谢谢

4

7 回答 7

1

flexlib ( http://code.google.com/p/flexlib/ ) 有一个可爱的 FlowContainer 容器控件,它将完全满足您的需要。

于 2010-02-16T04:07:43.030 回答
0

我用一个 HBox 和 2 个表单做了类似的事情,这很好地排列了起来。动态地,您可以交替向每个表单添加子级。

于 2010-02-01T17:46:17.200 回答
0

把它们放在一个 HBox 里?

于 2010-02-01T16:52:05.563 回答
0

您可以为每一行使用一个包含一个 HBox 的 VBox,并简单地用 2 个项目填充每个 HBox,例如:

var vb:VBox;
var array_of_items:数组;

for(var i:int = 0; i < array_of_items.length; i+=2)
{
var hb:Hbox = new HBox();
hb.addChild(array_of_items[i]);
hb.addChild(array_of_items[i+1]);
vb.addChild(hb);
}

于 2010-02-01T17:02:29.193 回答
0

我认为方向=“水平”的瓷砖容器会做到这一点

于 2010-06-24T11:15:16.433 回答
0

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

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 事件,然后将子项重新排列为两个 VBox 控件。

于 2010-02-03T16:56:40.457 回答
0

为什么不直接使用 Tile Container,并将 direction 属性设置为您需要的流向?

于 2010-02-01T20:58:56.240 回答