Flex Gumbo中如何通过skinClass样式和requestedRowCount属性设置DropDownList行数的例子

By Minidxer | August 5, 2009

接下来的Flex Gumbo中如何通过skinClass样式自定义DropDownList皮肤和通过requestedRowCount属性设置下拉行数。



下面是main.mxml:

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <s:Application name="DropDownList_skinClass_requestedRowCount_test"
  3.         xmlns:fx="http://ns.adobe.com/mxml/2009"
  4.         xmlns:s="library://ns.adobe.com/flex/spark"
  5.         xmlns:mx="library://ns.adobe.com/flex/halo">
  6.     <s:layout>
  7.         <s:BasicLayout />
  8.     </s:layout>
  9.  
  10.     <s:DropDownList id="comboBox"
  11.             skinClass="skins.CustomDropDownListSkin"
  12.             width="100"
  13.             horizontalCenter="0"
  14.             top="20">
  15.         <s:dataProvider>
  16.             <s:ArrayList source="[The,quick,brown,fox,jumps,over,the,lazy,dog]" />
  17.         </s:dataProvider>
  18.     </s:DropDownList>
  19.  
  20. </s:Application>

下面是CustomDropDownListSkin.mxml的代码:

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <s:SparkSkin name="CustomDropDownListSkin"
  3.         xmlns:fx="http://ns.adobe.com/mxml/2009"
  4.         xmlns:s="library://ns.adobe.com/flex/spark">
  5.     <s:states>
  6.         <s:State name="normal" />
  7.         <s:State name="open" />
  8.         <s:State name="disabled" />
  9.     </s:states>
  10.  
  11.     <s:transitions>
  12.         <s:Transition fromState="open" toState="normal">
  13.             <s:Sequence targets="{[popup]}">
  14.                 <s:Fade duration="150"/>
  15.                 <s:SetAction property="open"/>
  16.             </s:Sequence>
  17.         </s:Transition>
  18.     </s:transitions>
  19.  
  20.     <!-- host component -->
  21.     <fx:Metadata>
  22.         [HostComponent("spark.components.DropDownList")]
  23.     </fx:Metadata>
  24.  
  25.     <s:PopUp id="popup" includeIn="open"
  26.             open.normal="false" open.open="true"
  27.             visible.open = "true" visible.normal="false"
  28.             left="0" right="0" top="0" bottom="0"
  29.             placement="below">
  30.         <s:List id="dropDown" skinClass="skins.CustomListSkin" minHeight="22">
  31.             <s:filters>
  32.                 <s:DropShadowFilter blurX="20" blurY="20" distance="5" angle="90" alpha="0.6" />
  33.             </s:filters>
  34.         </s:List>
  35.     </s:PopUp>
  36.  
  37.     <s:Button id="button"
  38.             skinClass="spark.skins.default.DropDownListButtonSkin"
  39.             focusEnabled="false"
  40.             width="100%" height="100%" />
  41.     <s:Group mouseChildren="false" mouseEnabled="false"
  42.             left="5" right="5" top="5" bottom="5">
  43.         <s:SimpleText id="labelElement" />
  44.     </s:Group>
  45.  
  46. </s:SparkSkin>

以及皮肤文件CustomListSkin.mxml:

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <s:SparkSkin name="CustomListSkin"
  3.         xmlns:fx="http://ns.adobe.com/mxml/2009"
  4.         xmlns:s="library://ns.adobe.com/flex/spark"
  5.         alpha.disabled="0.5">
  6.     <s:states>
  7.         <s:State name="normal" />
  8.         <s:State name="disabled" />
  9.     </s:states>
  10.  
  11.     <fx:Metadata>
  12.         [HostComponent("spark.components.List")]
  13.     </fx:Metadata>
  14.  
  15.     <fx:Script>
  16.         /* Define the skin elements that should not be colorized.
  17.            For list, the skin itself is colorized but the individual parts are not. */
  18.         static private const exclusions:Array = ["scroller", "background"];
  19.         override public function get colorizeExclusions():Array {return exclusions;}
  20.  
  21.         /* Define the content fill items that should be colored by the "contentBackgroundColor" style. */
  22.         static private const contentFill:Array = ["bgFill"];
  23.         override public function get contentItems():Array {return contentFill};
  24.     </fx:Script>
  25.  
  26.     <!-- border -->
  27.     <s:Rect left="0" right="0" top="0" bottom="0">
  28.         <s:stroke>
  29.             <s:SolidColorStroke color="0x686868" weight="1"/>
  30.         </s:stroke>
  31.     </s:Rect>
  32.  
  33.     <!-- fill -->
  34.     <s:Rect id="background" left="1" right="1" top="1" bottom="1" >
  35.         <s:fill>
  36.             <s:SolidColor id="bgFill" color="0xFFFFFF" />
  37.         </s:fill>
  38.     </s:Rect>
  39.  
  40.     <s:Scroller left="1" top="1" right="1" bottom="1" id="scroller">
  41.         <s:DataGroup id="dataGroup" itemRenderer="spark.skins.default.DefaultItemRenderer">
  42.             <s:layout>
  43.                 <s:VerticalLayout gap="0" requestedRowCount="3" horizontalAlign="contentJustify" />
  44.             </s:layout>
  45.         </s:DataGroup>
  46.     </s:Scroller>
  47.  
  48. </s:SparkSkin>
代码:Peter deHaan 翻译/整理/编译:中文Flex例子

Topics: DropDownList, Gumbo | No Comments » | Tags: , ,

Search Posts