2010-02-25 39 views
2

我想从xml文件填充horizo​​ntalList组件,宽度值将在xml文件中以及所有数据。Horizo​​ntallist可变宽度

其实我有这样的代码:

<mx:Model id="epg" source="epg.xml" /> 

<mx:Component id="customRend"> 
    <mx:Label text="{data.description}" width="{data.width}"/> 
</mx:Component> 

<mx:HBox x="82" y="104" width="1203" height="113" verticalAlign="middle"> 
    <mx:HorizontalList width="100%" dataProvider="{epg.channel.program}" 
     itemRenderer="{customRend}" horizontalScrollPolicy="off"> 
    </mx:HorizontalList> 
</mx:HBox> 

但它设置相同的宽度为列表中的所有元素。

你知道如何做到这一点吗?

非常感谢。 溴

回答

0

两种方法可以做到这一点:

  • 在画布

creationComplete

  • 包装标签设置label.width = data.width的creationComplete方式(可能是因为itemRenderer的应该是一个容器?):

    <mx:HorizontalList width="100%" dataProvider="{epg.channel.program}" horizontalScrollPolicy="off"> 
        <mx:itemRenderer> 
         <mx:Component id="customRend"> 
          <mx:Label text="{data.description}" creationComplete="this.width = data.width"/> 
         </mx:Component> 
        </mx:itemRenderer> 
    </mx:HorizontalList> 
    

    ...或w敲击在画布:

    <mx:HorizontalList width="100%" dataProvider="{epg.channel.program}" horizontalScrollPolicy="off"> 
        <mx:itemRenderer> 
         <mx:Component id="customRend"> 
          <mx:Canvas horizontalScrollPolicy="off"> 
           <mx:Label text="{data.description}" width="{data.width}"/> 
          </mx:Canvas> 
         </mx:Component> 
        </mx:itemRenderer> 
    </mx:HorizontalList> 
    

    希望帮助, 兰斯

  • +0

    感谢您的帮助。 我试过这段代码,但仍然是同样的问题。所有元素的宽度总是相同的,我对此没有任何暗示:-( – 2010-02-25 11:56:15

    +0

    你使用的是什么版本的Flex?它对我有用 – 2010-02-25 21:53:33

    +0

    我有Flex Builder 3, 我真正想要实现的是像这个http://jaganath.files.wordpress.com/2006/12/guide.PNG,也许有其他更容易的组件,我可以使用... – 2010-02-26 05:59:21