中继器内的组件未按预期调整大小
我有一个 mxml 面板,在其中使用中继器。面板可以水平调整大小,我希望重复的组件与面板一起调整大小。下面是一个简化的示例:
<mx:TitleWindow xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical" ...>
<!-- scripts and some controls -->
<mx:VBox width="100%">
<core:Repeater width="100%" dataProvider="model">
<ns1:MyItemRenderer width="100%" />
</core:Repeater>
</mx:VBox>
</mx:TitleWindow>
当我调整组件大小时,重复项目的宽度不会改变。
还有按钮和事件处理程序,用于在模型中添加和删除项目。完成此操作后,中继器会更新以显示正确的项目数量,并且所有项目的大小都会正确调整。
当根面板调整大小时,我无法调整项目的大小。我可以看到,中继器周围的 VBOx 正在接收调整大小事件。然而,重复的项目没有得到事件。我尝试从连接到 VBox 的调整大小处理程序手动向重复项目发送调整大小事件,但这没有帮助。
我还尝试从 ArrayCollection 中添加和删除一个虚拟项目,即 dataProvider(因为这会触发正确的调整大小,否则如上所述)但是,在 VBox 的调整大小处理程序中执行此操作只会导致中继器在以下位置不显示任何项目全部。
有没有什么方法可以让中继器中的项目随其封闭容器调整大小?
我使用的 ItemRenderer 在 mx:List 中使用时可以正确调整大小。它的构建使得它可以与 List 容器设置的数据属性和在 Repeater 中使用时的 getRepeaterItem() 一起使用。在这种特殊情况下,我无法使用 List 作为容器,因为它通过 rowCount、height 和 maxHeight 属性控制其高度的行为方式在这种特殊情况下对我来说不起作用(我省去了细节)。
I have an mxml panel in which I'm using a repeater. The panel can be resized horizontally and I would like for the repeated components to resize together with panel. Here is a simplified example of how things look like:
<mx:TitleWindow xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical" ...>
<!-- scripts and some controls -->
<mx:VBox width="100%">
<core:Repeater width="100%" dataProvider="model">
<ns1:MyItemRenderer width="100%" />
</core:Repeater>
</mx:VBox>
</mx:TitleWindow>
When I resize the component, the width of the repeated items does not change.
There also buttons and event handlers, which add and remove items from the model. When this is done, the repeater updates to display the correct number of items and all the items are resized correctly.
I have not been able to get the items to resize when the root panel is resized. I can see, that the VBOx around the repeater is getting a resize event. However, the repeated items are not getting the event. I tried to dispatch a resize event to the repeated items manually from a resize handler I hooked up to the VBox but that didn't help.
I also tried adding and removing a dummy-item from the ArrayCollection which is the dataProvider (because that triggers a correct resize otherwise as mentioned above) However, doing this in the resize handler of the VBox just leads to the repeater not showing any items at all.
Is there any way to get items in a repeater to resize with their enclosing container?
The ItemRenderer I'm using resizes correctly when used in a mx:List. It is built so it can work both with the data property set by the List container an getRepeaterItem() when used in a Repeater. In this particular case, I cannot use the List as a container because of the way it behaves with regards to controlling its height via the rowCount, height and maxHeight properties which doesn't work out for me in this particular case (I spare you the details).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
覆盖 titleWindow 中的 updateDisplayList,并且当高度或宽度更改时,使转发器内创建的每个项目上的 displayList 无效。
也就是说,使用中继器通常被认为是不好的做法,因为其中的每个组件都会被渲染。基于列表的类——利用渲染器回收被认为具有更高的性能。
根据您的代码段,我无法判断您的代码是否可以在没有中继器的情况下重新工作。
override updateDisplayList in the titleWindow and when the height or width changes, invalidate the displayList on every item created inside the repeater.
That said, using repeaters are generally considered bad practice because every component inside it is rendered. A list based class--which makes use of renderer recyling is considered to be much more performant.
Based on your code segment, I can't tell whether your code could be re-worked without repeaters, or not.
作为记录,我想出了以下“解决方案”:
在封装中继器的盒子上使用 maxHeight 属性,将其绑定到从其他组件派生正确值的表达式...我仍然需要对我想要的任何空间进行硬编码如果我不想将它们从封闭面板中推出,则可以保留包含中继器的盒子后面的组件,但目前已经足够了。
本质上:
For the record, I figured out the following "solution":
Use the maxHeight attribute on the box enclosing the repeater, binding it to an expression that derives the correct value from the other components... I still need to hardcode any space I want to reserve for components that come after the box containing the repeater if I don't want to have them pushed out of the enclosing panel but it is good enough for now.
essentially: