Flex Gumbo中如何设置DropDownList弹出菜单宽度的例子

By Minidxer | August 12, 2009

接下来的Flex Gumbo中如何通过width属性,设置DropDownList弹出菜单宽度。



下面是main.mxml:

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <s:Application name="Spark_DropDownList_skinClass_width_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.  
  7.     <s:DropDownList id="dropDownList"
  8.             labelField="label"
  9.             requiresSelection="true"
  10.             skinClass="skins.CustomDropDownListSkin"
  11.             horizontalCenter="0"
  12.             top="20">
  13.         <s:dataProvider>
  14.             <s:ArrayList>
  15.                 <fx:Object label="Adobe AIR" />
  16.                 <fx:Object label="ColdFusion" />
  17.                 <fx:Object label="Dreamweaver" />
  18.                 <fx:Object label="Flash" />
  19.                 <fx:Object label="Flash Player" />
  20.                 <fx:Object label="Fireworks" />
  21.                 <fx:Object label="Flex" />
  22.                 <fx:Object label="Illustrator" />
  23.             </s:ArrayList>
  24.         </s:dataProvider>
  25.     </s:DropDownList>
  26.  
  27. </s:Application>

下面是Skin类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.         alpha.disabled="0.5">
  6.     <s:states>
  7.         <s:State name="normal" />
  8.         <s:State name="open" />
  9.         <s:State name="disabled" />
  10.     </s:states>
  11.  
  12.     <!-- host component -->
  13.     <fx:Metadata>
  14.         [HostComponent("spark.components.DropDownList")]
  15.     </fx:Metadata>
  16.  
  17.     <s:PopUp id="popup"  open.normal="false" open.open="true" includeIn="open"
  18.             left="0" right="0" top="0" bottom="0"
  19.             visible.open="true" visible.normal="false"
  20.             placement="below">
  21.         <s:Group id="dropDown"
  22.                 maxHeight="134" minHeight="22" visible.open="true" visible.normal="false"
  23.                 width="200">
  24.             <!-- border -->
  25.             <s:Rect left="0" right="0" top="0" bottom="0">
  26.                 <s:stroke>
  27.                     <s:SolidColorStroke color="0x686868" weight="1"/>
  28.                 </s:stroke>
  29.             </s:Rect>
  30.  
  31.             <!-- fill -->
  32.             <s:Rect id="background" left="1" right="1" top="1" bottom="1" >
  33.                 <s:fill>
  34.                     <s:SolidColor id="bgFill" color="0xFFFFFF" />
  35.                 </s:fill>
  36.             </s:Rect>
  37.  
  38.             <s:Scroller left="1" top="1" right="1" bottom="1" >
  39.                 <s:DataGroup id="dataGroup" itemRenderer="spark.skins.default.DefaultItemRenderer">
  40.                     <s:layout>
  41.                         <s:VerticalLayout gap="0" horizontalAlign="contentJustify"/>
  42.                     </s:layout>
  43.                 </s:DataGroup>
  44.             </s:Scroller>
  45.  
  46.             <s:filters>
  47.                 <s:DropShadowFilter blurX="20" blurY="20" distance="5" angle="90" alpha="0.6" />
  48.             </s:filters>
  49.         </s:Group>
  50.     </s:PopUp>
  51.  
  52.     <s:Button id="button" left="0" right="0" top="0" bottom="0" focusEnabled="false"
  53.         skinClass="spark.skins.default.DropDownListButtonSkin" />
  54.  
  55.     <s:SimpleText id="labelElement" verticalAlign="middle"
  56.         left="7" right="30" top="2" bottom="2" verticalCenter="1" />
  57.  
  58. </s:SparkSkin>
代码:Peter deHaan 翻译/整理/编译:中文Flex例子

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

Search Posts