flex 3.5:如何在<mx:list>的末尾滚动?</mx:list>

时间:2014-04-08 15:30:10

标签: flex flex3

我使用flex3.5,我有一个

<mx:List id="globalchat_txt" x="0" y="0" width="100%" height="100%" variableRowHeight="true"  dataProvider="{messages}" itemRenderer="chat.MessageChat">

我在邮件中添加了一些项目。

    var message:Message = new Message(txt);
globalchat_txt.validateNow();
messages.addItem(message);
globalchat_txt.scrollToIndex(messages.length+1);
globalchat_txt.verticalScrollPosition = 99999;
globalchat_txt.validateNow();

我无法将列表滚动到最后位置! 它会进入最后一个位置,但总有10-15像素缺失!

enter image description here

2 个答案:

答案 0 :(得分:1)

这是Flex中List(spark和mx)的已知问题。

可以通过以下方法解决(由flexponential建议):

public static function scrollToBottom(list:List):void {
    // update the verticalScrollPosition to the end of the List
    // virtual layout may require us to validate a few times
    var delta:Number = 0;
    var count:int = 0;

    while (count++ < 10) {
        list.validateNow();
        delta = list.layout.getVerticalScrollPositionDelta(NavigationUnit.END);
        list.layout.verticalScrollPosition += delta;

        if (delta == 0)
            break;
    }
}

我前段时间也将此问题报告为bug #33660 for Apache Flex ......

答案 1 :(得分:1)

我们也遇到了这个问题。试试这个,扩展列表并覆盖scrollToIndex函数(FLEX SDK3.5)

override public function scrollToIndex(index:int):Boolean
    {
        // when index=-1, do nothing
        if (index == -1)
            return false;

        var success:Boolean = super.scrollToIndex(index);
        if (success)
        {
            return true;
        }

        // if doesn't show complete, immediately scroll down
        var item:ListRowInfo = rowInfo[index - verticalScrollPosition];
        if (item.height + item.y > height)
        {
            verticalScrollPosition += 1;
            return true;
        }

        return false;
    }