簡體   English   中英

Flex項呈示器 - 單擊時更改alpha

[英]Flex item renderer - change alpha when clicked

我想在單擊列表項時更改Rect的alpha,但我無法解決。 而且我不知道這是怎么做的,因為我在項目渲染器內的Rectangle上這樣做,有什么建議嗎?

碼:

<s:List id="list" labelField="name" dataProvider="{items}" top="20" bottom="20" left="20" right="20" 
                contentBackgroundAlpha="0"
                change="list_changeHandler(event)">
            <s:itemRenderer>
                <fx:Component>
                    <s:ItemRenderer width="100%" height="200" autoDrawBackground="false" contentBackgroundAlpha="0">

                        <s:Group width="100%" height="100%">
                            <s:Rect id="rect" left="0" right="0" top="0" bottom="0" alpha="0.3">
                                <s:fill>
                                    <s:SolidColor color="#FFFFFF" 
                                                   />
                                </s:fill>
                            </s:Rect>
                            <s:Image source="{data.icon}" top="30" horizontalCenter="0"/>
                            <s:Label text="{data.name}" top="100" horizontalCenter="0" color="#101010" fontWeight="bold" fontSize="16"/>
                            <s:Label text="{data.line1}" top="130" horizontalCenter="0" color="#343434" fontSize="14"/>
                            <s:Label text="{data.line2}" top="150" horizontalCenter="0" color="#343434" fontSize="14"/>
                        </s:Group>
                    </s:ItemRenderer>
                </fx:Component>
            </s:itemRenderer>
            <s:layout>
                <s:TileLayout requestedColumnCount="3" requestedColumnCount.landscape="4" columnAlign="justifyUsingWidth"/>
            </s:layout>
        </s:List>

您可以使用ItemRenderer的狀態。 將這些狀態添加到ItemRenderer:

<s:states>
    <s:State name="normal" />
    <s:State name="hovered" />
    <s:State name="selected" />
</s:states>

<s:Rect left="0" right="0" top="0" bottom="0">
    <s:fill>
        <s:SolidColor color.normal="0x0000ff" 
                      color.hovered="0x00ff00" 
                      color.selected="0xff0000" />
    </s:fill>
</s:Rect>

使用此代碼,您的渲染器默認為藍色; 當你將鼠標懸停在它上面時會變綠; 選擇它時為紅色。 當然可以使用alpha值完成相同的操作。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM