为什么ConstraintLayout无法重用?我想在ItemRenderer中布局一个Group,我的目的是将一次性创建的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>