0

以下代码使用 List 控件显示注释列表。项目高度设置为固定值(150),所以它似乎工作:如果内容太长,滚动条显示......

但是,我真正想要的不是设置高度,而是让它根据内容大小而变化。有没有办法做到这一点?

        <mx:List id="commentList" width="100%" dataProvider="{commentSet.commentArrayColl}"
            rowCount="{commentSet.commentArrayColl.length}" >
            <mx:itemRenderer>
                <mx:Component>
                    <mx:VBox width="100%" height="150" >
                        <mx:Text text="{data.commentContent}" />
                        <mx:Text text="{data.username} ({data.modified})"/>
                    </mx:VBox>
                </mx:Component>
            </mx:itemRenderer>
        </mx:List> 

编辑:更清楚地说,我不想将 itemRenderer 的 VBox 高度设置为“150”或任何其他固定值 - 但如果我不这样做,它只会显示一行文本。所以我正在寻找摆脱这种情况的方法。(如果 VBox 不在 itemRenderer 内,它会随着文本字段字符串长度的增长自动调整高度 - 这就是我想要的。)

4

2 回答 2

3

添加一个绑定dataProvider.length * 150函数的height属性:

    <mx:List id="commentList" width="100%" dataProvider="{commentSet.commentArrayColl}"
        rowCount="{commentSet.commentArrayColl.length}" height={commentSet.commentArrayColl.length*150}>
        <mx:itemRenderer>
            <mx:Component>
                <mx:VBox width="100%" height="150" >
                    <mx:Text text="{data.commentContent}" />
                    <mx:Text text="{data.username} ({data.modified})"/>
                </mx:VBox>
            </mx:Component>
        </mx:itemRenderer>
    </mx:List>
于 2010-06-17T07:04:27.973 回答
1

尽量不要在 VBox 上设置高度,在列表中将 variableRowHeight 设置为 true。虽然我不确定 List 会如何发挥作用。

或者,由于您并没有真正使用 itemRender 回收的优势(因为 rowCount = dataProvider.length),您可能需要考虑使用中继器而不是列表。

于 2010-06-17T10:18:40.713 回答