Jul 05

接下来的例子演示了Flex的ComboBox控件中,如何利用dropdown属性中的variableRowHeight属性,创建可变高度的行。

让我们先来看一下Demo(可以右键View Source或点击这里察看源代码):


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

Download: main.mxml
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
  3.         layout="vertical"
  4.         verticalAlign="top"
  5.         backgroundColor="white">
  6.  
  7.     <mx:Script>
  8.         <![CDATA[
  9.             import mx.events.DropdownEvent;
  10.  
  11.             private function comboBox_open(evt:DropdownEvent):void {
  12.                 evt.currentTarget.dropdown.variableRowHeight = true;
  13.             }
  14.         ]]>
  15.     </mx:Script>
  16.  
  17.     <mx:Array id="arr">
  18.         <mx:Object name="Baltimore Orioles" abbr="BAL" />
  19.         <mx:Object name="Boston Red Sox" abbr="BOS" />
  20.         <mx:Object name="Chicago White Sox" abbr="CWS" />
  21.         <mx:Object name="Cleveland Indians" abbr="CLE" />
  22.         <mx:Object name="Detroit Tigers" abbr="DET" />
  23.         <mx:Object name="Kansas City Royals" abbr="KC" />
  24.         <mx:Object name="Los Angeles Angels of Anaheim" abbr="LAA" />
  25.         <mx:Object name="Minnesota Twins" abbr="MIN" />
  26.         <mx:Object name="New York Yankees" abbr="NYY" />
  27.         <mx:Object name="Oakland Athletics" abbr="OAK" />
  28.         <mx:Object name="Seattle Mariners" abbr="SEA" />
  29.         <mx:Object name="Tampa Bay Devil Rays" abbr="TB" />
  30.         <mx:Object name="Texas Rangers" abbr="TEX" />
  31.         <mx:Object name="Toronto Blue Jays" abbr="TOR" />
  32.     </mx:Array>
  33.  
  34.     <mx:ComboBox id="comboBox"
  35.             dataProvider="{arr}"
  36.             width="140"
  37.             labelField="name"
  38.             open="comboBox_open(event);">
  39.         <mx:itemRenderer>
  40.             <mx:Component>
  41.                 <mx:Text selectable="false"
  42.                         toolTip="{data.name} ({data.abbr})" />
  43.             </mx:Component>
  44.         </mx:itemRenderer>
  45.     </mx:ComboBox>
  46.  
  47. </mx:Application>
代码:Peter deHaan 翻译/整理/编译:minidxer

written by Minidxer  |  tags: , ,

Related Post

Leave a Reply