Flex 树中 MXTreeItemRenderer 中自动换行的高度问题
使用默认的 TreeItemrenderer,可以通过在树控件中设置 wordWrap=true
和 variableRowHeight="true"
来根据树宽度启用自动换行。
我想在 MXTreeItemRenderer (使用 Spark 组件作为 mx itemrenderer 的包装器)中启用此行为。 我使用了 Flexbuilder 创建的 MXTreeItemRenderer 并向标签组件添加了 100% 的宽度(请参见下面的代码)。
自动换行现在可以正常工作,但在许多情况下,当存在换行符时,项目渲染器高度的计算是错误的。它似乎适用于固定宽度。
知道如何解决这个问题吗?
<s:MXTreeItemRenderer xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx">
<s:states>
<s:State name="normal" />
<s:State name="hovered" />
<s:State name="selected" />
</s:states>
<s:HGroup left="0" right="0" top="0" bottom="0" verticalAlign="middle">
<s:Rect id="indentationSpacer" width="{treeListData.indent}" percentHeight="100" alpha="0">
<s:fill>
<s:SolidColor color="0xFFFFFF" />
</s:fill>
</s:Rect>
<s:Group id="disclosureGroup">
<s:BitmapImage source="{treeListData.disclosureIcon}" visible="{treeListData.hasChildren}" />
</s:Group>
<s:BitmapImage source="{treeListData.icon}" />
<s:Label id="labelField" text="{treeListData.label}" paddingTop="2" width="100%"/>
</s:HGroup>
</s:MXTreeItemRenderer>
With the default TreeItemrenderer it is possible to enable automatic word wrapping depending on the tree width by setting wordWrap=true
and variableRowHeight="true"
in the tree control.
I would like to enable this behavior in a MXTreeItemRenderer (a wrapper for using spark components as mx itemrenderer).
I used the MXTreeItemRenderer created by Flexbuilder and added a width of 100% to the label component (see code below).
Word wrapping is working now but in many cases the calculation of the item renderer height is wrong when there are line breaks. It seems to work with a fixed width.
Any idea how to get this right?
<s:MXTreeItemRenderer xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx">
<s:states>
<s:State name="normal" />
<s:State name="hovered" />
<s:State name="selected" />
</s:states>
<s:HGroup left="0" right="0" top="0" bottom="0" verticalAlign="middle">
<s:Rect id="indentationSpacer" width="{treeListData.indent}" percentHeight="100" alpha="0">
<s:fill>
<s:SolidColor color="0xFFFFFF" />
</s:fill>
</s:Rect>
<s:Group id="disclosureGroup">
<s:BitmapImage source="{treeListData.disclosureIcon}" visible="{treeListData.hasChildren}" />
</s:Group>
<s:BitmapImage source="{treeListData.icon}" />
<s:Label id="labelField" text="{treeListData.label}" paddingTop="2" width="100%"/>
</s:HGroup>
</s:MXTreeItemRenderer>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
好吧,您可能应该首先提交一个错误;)
如果它没有正确报告高度,请重写measure(..)方法并自己计算出高度,您可能必须使用线度量(如果它们仍然存在于Spark)来解决这个问题。
Well you should probably file a bug first off ;)
If it's not reporting the height correctly, override the measure(..) method and work out the height yourself, you'll probably have to use line metrics (If they are still around in Spark) to work it out.
我发现做两次后高度计算正确。
因此,作为现在的解决方法,我监听数据和大小的更改,并在更改时调用树的
invalidateList()
方法。I found out that the height is calculated correctly when it is done twice.
So as a workaround for now I listen to changes of the data and the size and call the
invalidateList()
Method of the tree on a change.在这个博客网站中,有人向我指出了这个 网站
非常好,它对我很有帮助。我认为它适用于不同的行高。带有换行文本的节点应该可以工作。
享受!
In this blog site, someone pointed me to this site
really nice one, it helped me. I think it works for varying row height. Nodes with wrapping text should work.
Enjoy!