ListItemRenderer背景颜色

问题描述 投票:1回答:1

使用flex4,我有一个包含项呈示器的列表:

<mx:List id="queueView" dataProvider="{presenter.queue.items}">
  <mx:itemRenderer>
    <fx:Component>
      <mx:VBox>
        <mx:Label text="{data.name}"/>
        <mx:Label text="{data.artist.name}"/>
      </mx:VBox>
    </fx:Component>
  </mx:itemRenderer>
</mx:List>

我在列表上有不同的颜色:

#queueView
{
  alternating-item-colors: red, yellow;
}

但是列表项总是以白色背景渲染(如果我摆脱了渲染器,它会正确渲染颜色)。

如果我在itemRenderer上设置contentBackgroundColor =“red”,则每个项目都是红色。编译器不接受透明。

如何让itemRenderer尊重列表的交替颜色?

actionscript-3 flex flex4
1个回答
1
投票

这对我来说似乎很好。这是我的代码:

<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" 
               xmlns:s="library://ns.adobe.com/flex/spark" 
               xmlns:mx="library://ns.adobe.com/flex/halo" minWidth="1024" minHeight="768" xmlns:components="components.*">
    <fx:Declarations>
        <!-- Place non-visual elements (e.g., services, value objects) here -->
    </fx:Declarations>

    <fx:Script>
        <![CDATA[
            import mx.collections.ArrayCollection;

            [Bindable]
            public var items:ArrayCollection = new ArrayCollection([{name:"foo",value:"bar"},
                                                                    {name:"foo",value:"bar"},
                                                                    {name:"foo",value:"bar"},
                                                                    {name:"foo",value:"bar"},
                                                                    {name:"foo",value:"bar"},
                                                                    {name:"foo",value:"bar"},
                                                                    {name:"foo",value:"bar"},
                                                                    {name:"foo",value:"bar"}]);

        ]]>
    </fx:Script>


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

        #queueView
        {
            alternating-item-colors: red, yellow;   
        }
    </fx:Style>

    <mx:List id="queueView" dataProvider="{items}" width="200">
        <mx:itemRenderer>
            <fx:Component>
                <mx:VBox>
                    <mx:Label text="{data.name}"/>
                    <mx:Label text="{data.value}"/>
                </mx:VBox>
            </fx:Component>
        </mx:itemRenderer>
    </mx:List>    
</s:Application>

这是结果:

result

你在运行什么构建?我正在运行过去几周发布的最新测试版。准确地构建4.0.0.253292。如果您还没有升级到最新版本,可以尝试清理项目。还要确保您的浏览器没有缓存swf,这有时会在文件大小没有显着变化时发生。

如果我错过了什么,请告诉我。但是你的代码似乎运行正常。

© www.soinside.com 2019 - 2024. All rights reserved.