开发者

Horizontallist variable width

i want to populate a horizontalList component from a xml file, the width value will be inside the xml file as well with all the data.

actually i have this code:

<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>

but it sets same width for all elements in the list.

开发者_运维百科

Do you know how to do this?

Thanks a lot. Br


Two ways to do this:

  • Set label.width = data.width on creationComplete
  • Wrap Label in Canvas

The creationComplete way (probably because an itemRenderer should be a Container?):

<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>

... or wrapped in Canvas:

<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>

Hope that helps, Lance

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜