Flex Gumbo中如何通过layout属性设置DropDownList布局的例子

By Minidxer | August 13, 2009

接下来的例子演示了Flex Gumbo中如何通过layout属性,设置DropDownList布局。

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


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

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <s:Application name="Spark_DropDownList_TileLayout_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.             width="100"
  13.             top="20">
  14.         <s:dataProvider>
  15.             <s:ArrayList>
  16.                 <fx:Object label="The" />
  17.                 <fx:Object label="Quick" />
  18.                 <fx:Object label="Brown" />
  19.                 <fx:Object label="Fox" />
  20.                 <fx:Object label="Jumps" />
  21.                 <fx:Object label="Over" />
  22.                 <fx:Object label="The" />
  23.                 <fx:Object label="Lazy" />
  24.                 <fx:Object label="Dog" />
  25.             </s:ArrayList>
  26.         </s:dataProvider>
  27.     </s:DropDownList>
  28.  
  29. </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="below" popUpWidthMatchesAnchorWidth="false">
  24.  
  25.         <!--- The drop down area of the skin. This includes borders, background colors, scrollers, and filters. -->
  26.         <s:Group id="dropDown" maxHeight="134" minHeight="22" >
  27.             <!-- drop shadow -->
  28.             <s:RectangularDropShadow blurX="20" blurY="20" alpha="1.0" distance="5" 
  29.                  angle="90" color="#000000" left="0" top="0" right="0" bottom="0"/>
  30.  
  31.             <!-- border -->
  32.             <s:Rect left="0" right="0" top="0" bottom="0">
  33.                 <s:stroke>
  34.                     <s:SolidColorStroke color="0x686868" weight="1"/>
  35.                 </s:stroke>
  36.             </s:Rect>
  37.  
  38.             <!-- fill -->
  39.             <!--- Defines the appearance of drop-down list's background fill. -->
  40.             <s:Rect id="background" left="1" right="1" top="1" bottom="1" >
  41.                 <s:fill>
  42.                     <!--- The color of the drop down's background fill. The default color is 0xFFFFFF. -->
  43.                     <s:SolidColor id="bgFill" color="0xFFFFFF" />
  44.                 </s:fill>
  45.             </s:Rect>
  46.  
  47.             <s:Scroller left="0" top="0" right="0" bottom="0" focusEnabled="false"
  48.                     minViewportInset="1" verticalScrollPolicy="on">
  49.                 <!--- The container for the data items in the drop-down list. -->
  50.                 <s:DataGroup id="dataGroup" itemRenderer="spark.skins.spark.DefaultItemRenderer">
  51.                     <s:layout>
  52.                         <s:TileLayout horizontalGap="0" verticalGap="0"
  53.                                 requestedColumnCount="3" requestedRowCount="2" columnWidth="100" />
  54.                     </s:layout>
  55.                 </s:DataGroup>
  56.             </s:Scroller>
  57.         </s:Group>
  58.     </s:PopUpAnchor>
  59.  
  60.     <!--- The anchor button used by the DropDownList. The default skin is DropDownListButtonSkin. -->
  61.     <s:Button id="openButton" left="0" right="0" top="0" bottom="0" focusEnabled="false"
  62.             skinClass="spark.skins.spark.DropDownListButtonSkin" />
  63.  
  64.     <!--- The prompt area of the DropDownList. -->
  65.     <s:SimpleText id="labelDisplay" verticalAlign="middle" maxDisplayedLines="1"
  66.             left="7" right="30" top="2" bottom="2" verticalCenter="1" /> 
  67.  
  68. </s:Skin>
代码:Peter deHaan 翻译/整理/编译:中文Flex例子

Topics: DropDownList, Gumbo | 1 Comment » | Tags: , , , ,

Search Posts