2010-02-25 75 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