为什么不能重用 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>