Apache flex Flex 4 ConstraintLayout不可重用

Apache flex Flex 4 ConstraintLayout不可重用,apache-flex,layout,flex4,reusability,Apache Flex,Layout,Flex4,Reusability,为什么ConstraintLayout不能被重用?我想在ItemRenderer中布局一个组,我的目的是将一次性创建的ConstraintLayout注入到每个ItemRenderer中。但这是行不通的。有没有比为每个ItemRenderer创建新布局更便宜的方法 <?xml version="1.0" encoding="utf-8"?> <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" x

为什么ConstraintLayout不能被重用?我想在ItemRenderer中布局一个组,我的目的是将一次性创建的ConstraintLayout注入到每个ItemRenderer中。但这是行不通的。有没有比为每个ItemRenderer创建新布局更便宜的方法

<?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/mx" 
           initialize="initializeHandler(event)" 
           xmlns:local="*"
           >

<fx:Script>
    <![CDATA[
        import mx.containers.utilityClasses.ConstraintColumn;
        import spark.layouts.ConstraintLayout;

        [Bindable] private var cLayout1 : ConstraintLayout;
        [Bindable] private var cLayout2 : ConstraintLayout;

        protected function initializeHandler(event:FlexEvent):void {
            // produce one two ConstraintLayouts, with the same constraintColumns
            var v : Vector.<ConstraintColumn> = new Vector.<ConstraintColumn>();
            var col : ConstraintColumn = new ConstraintColumn();
            col.width = 100;
            v.push(col);
            col = new ConstraintColumn();
            col.width = 150;
            v.push(col);
            cLayout1 = new ConstraintLayout();
            cLayout1.constraintColumns = v;  
            cLayout2 = new ConstraintLayout();
            cLayout2.constraintColumns = v; 
        }

    ]]>
</fx:Script>
<s:VGroup width="100%" gap="3">
    <!-- works fine: -->
    <s:Group layout="{cLayout1}" >
        <s:Label left="col1:0" text="A1" />
        <s:Label left="col2:0" text="B1" />
    </s:Group>

    <!-- reuse cLayout1 does not work: (nothing is shown) -->
    <s:Group layout="{cLayout1}" >
        <s:Label left="col1:0" text="A2" />
        <s:Label left="col2:0" text="B2" />
    </s:Group>

    <!-- reuse of the vector, but new Layout is ok: -->
    <s:Group layout="{cLayout2}" >
        <s:Label left="col1:0" text="A3" />
        <s:Label left="col2:0" text="B3" />
    </s:Group>
</s:VGroup>

</s:Application>

=新向量。();
var col:ConstraintColumn=new ConstraintColumn();
柱宽=100;
v、 推(col);
col=新的ConstraintColumn();
柱宽=150;
v、 推(col);
cLayout1=新的ConstraintLayout();
cLayout1.constraintColumns=v;
cLayout2=新的ConstraintLayout();
cLayout2.2约束柱=v;
}
]]>

您需要创建一个单独的类,比如公共类MyLayout extends ConstraintLayout,而不是实例化ConstraintLayout并尝试重用它。设置该类中的所有列和行。然后在你想使用它的每个组上。谢谢你的提示。同时,我通过编写自己的constraintlayout(某种)实现来解决这个问题,它可以更轻松地设置布局比例。工作正常且可重复使用:-)