如何扩展列表以添加 UI 组件?

发布于 2024-10-20 07:29:11 字数 33 浏览 3 评论 0原文

如何扩展 Spark 列表以在其上添加 UI 组件?

How can I extend a spark list to add a UI component on it?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

你对谁都笑 2024-10-27 07:29:11

我假设您想要向列表本身内的项目添加 UI 组件,在这种情况下您可以使用 itemRenderers。有 几个 示例就在那里。

我从 Flex 示例(很棒的网站)如下。

MyApplication.mxml:

<?xml version="1.0" encoding="utf-8"?>
<!-- http://blog.flexexamples.com/2010/01/27/creating-a-fancy-spark-list-control-item-renderer-in-flex-4/ -->
<s:Application name="Spark_List_itemRenderer_test"
        xmlns:fx="http://ns.adobe.com/mxml/2009"
        xmlns:s="library://ns.adobe.com/flex/spark"
        xmlns:mx="library://ns.adobe.com/flex/mx"
        xmlns:local="*">

    <fx:Style>
        @namespace s "library://ns.adobe.com/flex/spark";

        s|List {
            chromeColor: #333333;
            color: white;
            contentBackgroundColor: black;
            fontSize: 24;
        }
    </fx:Style>

    <s:List id="list"
            itemRenderer="CustomListItemRenderer"
            labelField="name"
            width="400"
            horizontalCenter="0" verticalCenter="0">
        <s:layout>
            <s:VerticalLayout horizontalAlign="justify" gap="0" requestedRowCount="6" />
        </s:layout>
        <s:dataProvider>
            <s:ArrayList>
                <local:ProductVO name="Adobe Illustrator CS5" icon="@Embed('ai_appicon-tn.gif')" />
                <local:ProductVO name="Adobe AIR 2.0" icon="@Embed('air_appicon-tn.gif')" />
                <local:ProductVO name="ColdFusion 9" icon="@Embed('cf_appicon-tn.gif')" />
                <local:ProductVO name="Dreamweaver CS5" icon="@Embed('dw_appicon-tn.gif')" />
                <local:ProductVO name="Flash Professional CS5" icon="@Embed('fl_appicon-tn.gif')" />
                <local:ProductVO name="Adobe Flash Player 10.1" icon="@Embed('fl_player_appicon-tn.gif')" />
                <local:ProductVO name="Fireworks CS5" icon="@Embed('fw_appicon-tn.gif')" />
                <local:ProductVO name="Flex 4.0" icon="@Embed('fx_appicon-tn.gif')" />
                <local:ProductVO name="Lightroom 2.0" icon="@Embed('lr_appicon-tn.gif')" />
                <local:ProductVO name="Photoshop CS5" icon="@Embed('ps_appicon-tn.gif')" />
            </s:ArrayList>
        </s:dataProvider>
    </s:List>

</s:Application>

CustomListItemRenderer.mxml:

<?xml version="1.0" encoding="utf-8"?>
<!-- http://blog.flexexamples.com/2010/01/27/creating-a-fancy-spark-list-control-item-renderer-in-flex-4/ -->
<s:ItemRenderer name="CustomListItemRenderer"
        xmlns:fx="http://ns.adobe.com/mxml/2009"
        xmlns:s="library://ns.adobe.com/flex/spark"
        autoDrawBackground="false">
    <s:layout>
        <s:HorizontalLayout verticalAlign="middle"
                paddingLeft="5" paddingRight="5"
                paddingTop="5" paddingBottom="5" />
    </s:layout>
    <s:states>
        <s:State name="normal" />
        <s:State name="hovered" />
        <s:State name="selected" />
    </s:states>

    <s:BitmapImage source="{data.icon}" />
    <s:Label text="{data.name}"
            textDecoration.hovered="underline"
            paddingLeft.selected="5"
            width="100%"
            maxDisplayedLines="1"
            showTruncationTip="true" />
    <s:Label text="»"
            scaleX="2" scaleY="2" />

</s:ItemRenderer>

最后是ProductVO.as:

/** http://blog.flexexamples.com/2010/01/27/creating-a-fancy-spark-list-control-item-renderer-in-flex-4/ */
package {
    public class ProductVO extends Object {

        [Bindable]
        public var name:String;

        [Bindable]
        public var icon:Class;
    }
}

I'm assuming you want to add a UI component to the items within the List itself, in which case you can use itemRenderers. There are several good examples out there.

I'm pasting a fairly fancy example from Flex Examples (great site) below.

MyApplication.mxml:

<?xml version="1.0" encoding="utf-8"?>
<!-- http://blog.flexexamples.com/2010/01/27/creating-a-fancy-spark-list-control-item-renderer-in-flex-4/ -->
<s:Application name="Spark_List_itemRenderer_test"
        xmlns:fx="http://ns.adobe.com/mxml/2009"
        xmlns:s="library://ns.adobe.com/flex/spark"
        xmlns:mx="library://ns.adobe.com/flex/mx"
        xmlns:local="*">

    <fx:Style>
        @namespace s "library://ns.adobe.com/flex/spark";

        s|List {
            chromeColor: #333333;
            color: white;
            contentBackgroundColor: black;
            fontSize: 24;
        }
    </fx:Style>

    <s:List id="list"
            itemRenderer="CustomListItemRenderer"
            labelField="name"
            width="400"
            horizontalCenter="0" verticalCenter="0">
        <s:layout>
            <s:VerticalLayout horizontalAlign="justify" gap="0" requestedRowCount="6" />
        </s:layout>
        <s:dataProvider>
            <s:ArrayList>
                <local:ProductVO name="Adobe Illustrator CS5" icon="@Embed('ai_appicon-tn.gif')" />
                <local:ProductVO name="Adobe AIR 2.0" icon="@Embed('air_appicon-tn.gif')" />
                <local:ProductVO name="ColdFusion 9" icon="@Embed('cf_appicon-tn.gif')" />
                <local:ProductVO name="Dreamweaver CS5" icon="@Embed('dw_appicon-tn.gif')" />
                <local:ProductVO name="Flash Professional CS5" icon="@Embed('fl_appicon-tn.gif')" />
                <local:ProductVO name="Adobe Flash Player 10.1" icon="@Embed('fl_player_appicon-tn.gif')" />
                <local:ProductVO name="Fireworks CS5" icon="@Embed('fw_appicon-tn.gif')" />
                <local:ProductVO name="Flex 4.0" icon="@Embed('fx_appicon-tn.gif')" />
                <local:ProductVO name="Lightroom 2.0" icon="@Embed('lr_appicon-tn.gif')" />
                <local:ProductVO name="Photoshop CS5" icon="@Embed('ps_appicon-tn.gif')" />
            </s:ArrayList>
        </s:dataProvider>
    </s:List>

</s:Application>

CustomListItemRenderer.mxml:

<?xml version="1.0" encoding="utf-8"?>
<!-- http://blog.flexexamples.com/2010/01/27/creating-a-fancy-spark-list-control-item-renderer-in-flex-4/ -->
<s:ItemRenderer name="CustomListItemRenderer"
        xmlns:fx="http://ns.adobe.com/mxml/2009"
        xmlns:s="library://ns.adobe.com/flex/spark"
        autoDrawBackground="false">
    <s:layout>
        <s:HorizontalLayout verticalAlign="middle"
                paddingLeft="5" paddingRight="5"
                paddingTop="5" paddingBottom="5" />
    </s:layout>
    <s:states>
        <s:State name="normal" />
        <s:State name="hovered" />
        <s:State name="selected" />
    </s:states>

    <s:BitmapImage source="{data.icon}" />
    <s:Label text="{data.name}"
            textDecoration.hovered="underline"
            paddingLeft.selected="5"
            width="100%"
            maxDisplayedLines="1"
            showTruncationTip="true" />
    <s:Label text="»"
            scaleX="2" scaleY="2" />

</s:ItemRenderer>

And finally ProductVO.as:

/** http://blog.flexexamples.com/2010/01/27/creating-a-fancy-spark-list-control-item-renderer-in-flex-4/ */
package {
    public class ProductVO extends Object {

        [Bindable]
        public var name:String;

        [Bindable]
        public var icon:Class;
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文