我正在尝试在Flex中创建一个嵌套列表,它将动态调整大小以在数据提供程序更改时显示所有子项。
这是一个说明问题的简化示例:
<mx:Script>
<![CDATA[
import mx.collections.ArrayCollection;
[Bindable]
public var outer:ArrayCollection = new ArrayCollection(["one", "two", "three"]);
[Bindable]
public var inner:ArrayCollection = new ArrayCollection([]);
public function addInnerListItems () : void {
inner.addItem("fish");
inner.addItem("mice");
inner.addItem("cats");
inner.addItem("bats");
}
]]>
</mx:Script>
<mx:Button label="Add inner list items" click="addInnerListItems()" />
<mx:List dataProvider="{outer}" rowCount="{outer.length}">
<mx:itemRenderer>
<mx:Component>
<mx:VBox>
<mx:Label text="{this.data}" />
<mx:List dataProvider="{outerDocument.inner}" rowCount="{outerDocument.inner.length}">
<mx:itemRenderer>
<mx:Component>
<mx:Label text="{this.data}" />
</mx:Component>
</mx:itemRenderer>
</mx:List>
</mx:VBox>
</mx:Component>
</mx:itemRenderer>
</mx:List>
添加项目时,列表大小保持不变。
如果我将variableRowHeight="true"
添加到外部列表,则内部列表将正确调整大小。但外部名单本身仍保持固定的大小。
如何让两个列表自动调整大小以显示所有孩子?
谢谢! 斯图
答案 0 :(得分:1)
覆盖列表类,并在新类中覆盖measure方法以计算measuredWidth和measuredHEight以计算值,就像所有列表项在屏幕上以全尺寸渲染一样。
然后覆盖包含嵌入列表的组件中的updateDisplayList(),将上面的列表调整为measuredWidth和measurdHeight。
但是,我不会轻易采取这种做法。如果您这样做,您将在屏幕上呈现所有项目,从而否定了渲染器首先使用List类的回收利益。