【问题标题】:flex 3.5: how to scroll at the end of the <mx:list>?flex 3.5:如何在 <mx:list> 的末尾滚动?
【发布时间】:2014-04-08 15:30:10
【问题描述】:

我用的是 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 像素丢失!

【问题讨论】:

    标签: apache-flex flex3


    【解决方案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...

    【讨论】:

      【解决方案2】:

      我们也遇到过这个问题。试试这个,扩展列表并覆盖 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;
          }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2020-08-09
        • 1970-01-01
        • 2016-02-15
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多