【问题标题】:Flex Get Width of List Item in Horizontal ListFlex获取水平列表中列表项的宽度
【发布时间】:2012-07-19 20:15:10
【问题描述】:

我的 Flex 应用程序中有列表 <s:List>,它水平显示其列表项,如下所示:

<s:List id="horzList">
  <s:Layout>
    <s:HorizontalLayout/>
  </s:Layout>

  <s:dataProvider>
    <s:ArrayList>
      <fx:String>Short Item</fx:String>
      <fx:String>Looooonnnnggggeeerrrrr Item</fx:String>
      <fx:String>A really, really, really long item for this list</fx:String>
    </s:ArrayList>
  </s:dataProvider>
</s:List>

使用change 事件,我如何获取水平列表中这些项目之一的宽度?

感谢您的宝贵时间。

【问题讨论】:

    标签: actionscript-3 flash apache-flex events flex4


    【解决方案1】:

    哇...这是一个肮脏的烂摊子,但我确实明白了。这是change 事件处理程序。顺便说一句,我的实际应用程序使用带有外部数据源的项目渲染器。话虽如此,除非您使用项目渲染器,否则我不知道下面的代码是否可以工作:

    private function changeHandler(e:IndexChangeEvent):void {
      var index:int = horzList.selectedIndex;
      var selected:IVisualElement = horzList.dataGroup.getElementAt(index);
      var width:Number = selected.width;
    
      //Do something with the width...
    }
    

    这个回答对我帮助很大:https://stackoverflow.com/a/4035185/663604

    希望对某人有所帮助。

    【讨论】:

    • 这也适用于默认项目渲染器,但我认为如果您向下滚动列表可能会遇到问题,因为 selectedIndex 不会对应于 dataGroup 中的子索引。
    猜你喜欢
    • 1970-01-01
    • 2017-07-18
    • 1970-01-01
    • 2011-10-08
    • 1970-01-01
    • 1970-01-01
    • 2023-03-05
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多