Flex教程:DropDownList中显示图片-网页
Flex Gumbo中如何通过itemRenderer属性,DropDownList中显示图片
Flex Gumbo中如何通过itemRenderer属性,DropDownList中显示图片
下面是main.mxml:
- <?xml
version="1.0" encoding="utf-8"?> - <s:Application
name="Spark_DropDownList_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/halo"> -
<s:DropDownList id="dropDownList" -
labelField="label" -
requireSelection="true" -
skinClass="skins.CustomDropDownListSkin" -
itemRenderer="spark.skins.spark.DefaultComplexItemRender er" -
horizontalCenter="0" -
top="20"> -
<s:dataProvider> -
<s:ArrayList> -
<s:BitmapImage source="@Embed('assets/air_appicon-tn.gif')" /> -
<s:BitmapImage source="@Embed('assets/cf_appicon-tn.gif')" /> -
<s:BitmapImage source="@Embed('assets/dw_appicon-tn.gif')" /> -
<s:BitmapImage source="@Embed('assets/fl_appicon-tn.gif')" /> -
<s:BitmapImage source="@Embed('assets/fl_player_appicon-tn.gif')" /> -
<s:BitmapImage source="@Embed('assets/fw_appicon-tn.gif')" /> -
<s:BitmapImage source="@Embed('assets/fx_appicon-tn.gif')" /> -
<s:BitmapImage source="@Embed('assets/ai_appicon-tn.gif')" /> -
</s:ArrayList> -
</s:dataProvider> -
</s:DropDownList> - </s:Application>
下面是skins/CustomDropDownListSkin.mxml的代码:
- <?xml
version="1.0" encoding="utf-8"?> - <s:Skin
name="CustomDropDownListSkin" -
xmlns:fx="http://ns.adobe.com/mxml/2009" -
xmlns:s="library://ns.adobe.com/flex/spark" -
alpha.disabled="0.5"> -
<!-- states --> -
<s:states> -
<s:State name="normal" /> -
<s:State name="open" /> -
<s:State name="disabled" /> -
</s:states> -
<!-- host component --> -
<fx:Metadata> -
<![CDATA[ -
[HostComponent("spark.components.DropDownList")] -
]]> -
</fx:Metadata> -
<!--- The PopUpAnchor control that opens the drop-down list. --> -
<s:PopUpAnchor id="popUp" displayPopUp.normal="false" displayPopUp.open="true" includeIn="open" -
left="0" right="0" top="0" bottom="0" itemDestructionPolicy="auto" -
popUpPosition="below" popUpWidthMatchesAnchorW idth="true"> -
<!--- The drop down area of the skin. This includes borders, background colors, scrollers, and filters. --> -
<s:Group id="dropDown" maxHeight="134" minHeight="22" > -
<!-- drop shadow --> -
<s:RectangularDropShadow blurX="20" blurY="20" alpha="1.0" distance="5" -
angle="90" color="#000000" left="0" top="0" right="0" bottom="0"/> -
<!-- border --> -
<s:Rect left="0" right="0" top="0" bottom="0"> -
<s:stroke> -
<s:SolidColorStroke color="0x686868" weight="1"/> -
</s:stroke> -
</s:Rect> -
<!-- fill --> -
<!--- Defines the appearance of drop-down list's background fill. --> -
<s:Rect id="background" left="1" right="1" top="1" bottom="1" > -
<s:fill> -
<!--- The color of the drop down's background fill. The default color is 0xFFFFFF. --> -
<s:SolidColor id="bgFill" color="0xFFFFFF" /> -
</s:fill> -
</s:Rect> -
<s:Scroller left="0" top="0" right="0" bottom="0" focusEnabled="false" minViewportInset="1"> -
<!--- The container for the data items in the drop-down list. --> -
<s:DataGroup id="dataGroup" itemRenderer="spark.skins.spark.DefaultItemRenderer"> -
<s:layout> -
<s:VerticalLayout gap="0" horizontalAlign="contentJustify"/> -
</s:layout> -
</s:DataGroup> -
</s:Scroller> -
</s:Group> -
</s:PopUpAnchor> -
<!--- The anchor button used by the DropDownList. The default skin is DropDownListButtonSkin. --> -
<s:Button id="openButton" left="0" right="0" top="0" bottom="0" focusEnabled="false" -
skinClass="spark.skins.spark.DropDownListButtonSkin" /> -
<s:BitmapImage source="{hostComponent.selectedItem.source}" -
left="10" right="30" top="10" bottom="10" /> - </s:Skin>