Flex Gumbo中如何通过placement属性设置DropDownList弹出位置的例子

By Minidxer | August 14, 2009

接下来的例子演示了Flex Gumbo中如何通过placement属性,设置DropDownList弹出位置。

让我们先来看一下Demo可以点击这里察看源代码):


下面是完整代码(或点击这里察看):
下面是main.mxml:

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <s:Application name="Spark_DropDownList_PopUp_placement_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.             requireSelection="true"
  10.             skinClass="skins.CustomDropDownListSkin"
  11.             horizontalCenter="0"
  12.             top="20">
  13.         <s:dataProvider>
  14.             <s:ArrayList>
  15.                 <fx:Object label="The" />
  16.                 <fx:Object label="Quick" />
  17.                 <fx:Object label="Brown" />
  18.                 <fx:Object label="Fox" />
  19.                 <fx:Object label="Jumps" />
  20.                 <fx:Object label="Over" />
  21.                 <fx:Object label="The" />
  22.                 <fx:Object label="Lazy" />
  23.                 <fx:Object label="Dog" />
  24.             </s:ArrayList>
  25.         </s:dataProvider>
  26.     </s:DropDownList>
  27.  
  28. </s:Application>

下面是skins/CustomDropDownListSkin.mxml的代码:

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <s:Skin 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.     <!-- states -->
  7.     <s:states>
  8.         <s:State name="normal" />
  9.         <s:State name="open" />
  10.         <s:State name="disabled" />
  11.     </s:states>
  12.  
  13.     <!-- host component -->
  14.     <fx:Metadata>
  15.     <![CDATA[
  16.         [HostComponent("spark.components.DropDownList")]
  17.     ]]>
  18.     </fx:Metadata> 
  19.  
  20.     <!--- The PopUpAnchor control that opens the drop-down list. -->
  21.     <s:PopUpAnchor id="popUp"  displayPopUp.normal="false" displayPopUp.open="true" includeIn="open"
  22.             left="0" right="0" top="0" bottom="0" itemDestructionPolicy="auto"
  23.             popUpPosition="left" popUpWidthMatchesAnchorWidth="true">
  24.         <!--- The drop down area of the skin. This includes borders, background colors, scrollers, and filters. -->
  25.         <s:Group id="dropDown" maxHeight="134" minHeight="22" >
  26.             <!-- drop shadow -->
  27.             <s:RectangularDropShadow blurX="20" blurY="20" alpha="1.0" distance="5" 
  28.                     angle="90" color="#000000" left="0" top="0" right="0" bottom="0"/>
  29.             <!-- border -->
  30.             <s:Rect left="0" right="0" top="0" bottom="0">
  31.                 <s:stroke>
  32.                     <s:SolidColorStroke color="0x686868" weight="1"/>
  33.                 </s:stroke>
  34.             </s:Rect>
  35.  
  36.             <!-- fill -->
  37.             <!---  Defines the appearance of drop-down list's background fill. -->
  38.             <s:Rect id="background" left="1" right="1" top="1" bottom="1" >
  39.                 <s:fill>
  40.                     <!--- The color of the drop down's background fill. The default color is 0xFFFFFF. -->
  41.                     <s:SolidColor id="bgFill" color="0xFFFFFF" />
  42.                 </s:fill>
  43.             </s:Rect>
  44.  
  45.             <s:Scroller left="0" top="0" right="0" bottom="0" focusEnabled="false" minViewportInset="1">
  46.                 <!--- The container for the data items in the drop-down list. -->
  47.                 <s:DataGroup id="dataGroup" itemRenderer="spark.skins.spark.DefaultItemRenderer">
  48.                     <s:layout>
  49.                         <s:VerticalLayout gap="0" horizontalAlign="contentJustify"/>
  50.                     </s:layout>
  51.                 </s:DataGroup>
  52.             </s:Scroller>
  53.         </s:Group>
  54.     </s:PopUpAnchor>
  55.  
  56.     <!--- The anchor button used by the DropDownList. The default skin is DropDownListButtonSkin. -->
  57.     <s:Button id="openButton" left="0" right="0" top="0" bottom="0" focusEnabled="false"
  58.             skinClass="spark.skins.spark.DropDownListButtonSkin" /> 
  59.     <!--- The prompt area of the DropDownList. -->
  60.     <s:SimpleText id="labelDisplay" verticalAlign="middle" maxDisplayedLines="1"
  61.             left="7" right="30" top="2" bottom="2" verticalCenter="1" /> 
  62.  
  63. </s:Skin>
代码:Peter deHaan 翻译/整理/编译:中文Flex例子

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

Search Posts