【问题标题】:Flex itemrenderer disable rollover but keep alternating colorsFlex itemrenderer 禁用翻转但保持交替颜色
【发布时间】:2011-06-01 08:31:07
【问题描述】:

有没有办法在不丢失交替背景颜色的情况下自定义项目渲染器的翻转和选定颜色?

当我将 autoDrawBackground 标志设置为 false 时,翻转效果会停止,但由于某种原因,交替背景也不会被绘制。

我想创建一个渲染器,它在悬停状态上绘制白色边框,在选中状态下绘制黄色边框,而不是默认的翻转颜色。 我还想保留我在列表中设置的交替背景颜色。

有什么建议吗?

【问题讨论】:

  • 有一个属性叫做“useRollOver”。设置为false,不要使用autoDrawBackground = false,因为这样会出问题。
  • useRollOver 仅适用于 MX 组件。 autoDrawBackground 仅适用于 List 控件,不适用于 DataGrids。

标签: apache-flex effects itemrenderer rollover


【解决方案1】:

您可以使用 ItemRenderer 类的“itemIndex”属性来绘制背景。例如:

override protected function updateDisplayList(unscaledWidth:Number,
                                              unscaledHeight:Number):void 
{
    backgroundFill.color = itemIndex % 2 ? 0xff0000 : 0x00ff00;
    super.updateDisplayList(unscaledWidth, unscaledHeight);
}

对于这样的背景图形,将在红色和绿色行之间交替:

<s:Rect id="background" left="0" right="0" top="0" bottom="0">
    <s:fill>
        <s:SolidColor id="backgroundFill" />
    </s:fill>
</s:Rect>

使用这种技术,你显然也可以做更复杂的事情,比如渐变、alphas 效果等等。

【讨论】:

  • 谢谢,这是我所缺少的。我将您的解决方案与 getStyle("alternatingItemColors") 结合使用来获取列表中设置的颜色,因此我不必将它们存储在渲染器中
【解决方案2】:
<s:states>
    <s:State name="normal"  />
    <s:State name="hovered"  />
    <s:State name="selected"  />
</s:states>

<s:BorderContainer backgroundColor.selected="0xA9C6EE" backgroundColor.normal="0xffffff" backgroundColor.hovered="0xCEDBEE" height="50" width="233">        

</s:BorderContainer>

如果我没有误解你的问题,我认为这就是你所需要的:)

【讨论】:

  • 这正是我所需要的。然而问题是我必须将 autoDrawBackground 设置为 false 否则默认的翻转效果也会触发。当我将此标志设置为 false 时,我在列表中设置的 alterrowcolors 不再起作用。我使用 RIAstar 的答案来使用 getStyle("alternatingItemColors") 来获取列表中设置的颜色数组
  • 你可以随意设置你的风格。例如"List.blueTheme { selectionColor: #7FACF6; }[link]tourdeflex.adobe.com/flex4.0/CSSTypeClassSelector/sample.html 可以查看详细的样式设置示例。
猜你喜欢
  • 1970-01-01
  • 2013-06-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-01-20
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多