Flex 树中 MXTreeItemRenderer 中自动换行的高度问题

发布于 2024-09-10 20:10:24 字数 1474 浏览 2 评论 0原文

使用默认的 TreeItemrenderer,可以通过在树控件中设置 wordWrap=truevariableRowHeight="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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

复古式 2024-09-17 20:10:24

好吧,您可能应该首先提交一个错误;)

如果它没有正确报告高度,请重写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.

这样的小城市 2024-09-17 20:10:24

我发现做两次后高度计算正确。
因此,作为现在的解决方法,我监听数据和大小的更改,并在更改时调用树的 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.

长发绾君心 2024-09-17 20:10:24

在这个博客网站中,有人向我指出了这个 网站

非常好,它对我很有帮助。我认为它适用于不同的行高。带有换行文本的节点应该可以工作。

享受!

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!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文