【问题标题】:Horizontallist variable widthHorizo​​ntallist 可变宽度
【发布时间】:2010-02-25 10:58:47
【问题描述】:

我想从 xml 文件中填充一个水平列表组件,宽度值将在 xml 文件中以及所有数据中。

其实我有这个代码:

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

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

你知道怎么做吗?

非常感谢。 Br

【问题讨论】:

    标签: apache-flex adobe width horizontallist


    【解决方案1】:

    两种方法:

    • creationComplete 上设置label.width = data.width
    • 在画布中环绕标签

    creationComplete方式(可能是因为一个itemRenderer应该是一个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>
    

    ... 或包裹在 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>
    

    希望对您有所帮助, 兰斯

    【讨论】:

    • 感谢您的帮助。我试过这段代码,但仍然是同样的问题。所有元素的宽度总是相同的,我对此没有任何暗示:-(
    • 我有 flex builder 3,我真正想要实现的是这样的东西 jaganath.files.wordpress.com/2006/12/guide.PNG,也许还有其他更简单的组件可以使用...
    猜你喜欢
    • 1970-01-01
    • 2014-02-13
    • 2012-10-04
    • 2014-03-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多