Flex中如何通过moveDivider()和getDividerAt()函数在程序代码中动态改变HDividedBox容器部分大小的例子

By Minidxer | October 17, 2008

接下来的例子演示了Flex中如何通过moveDivider()和getDividerAt()函数,在程序代码中动态改变HDividedBox容器部分大小

让我们先来看一下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="middle"
  5.         backgroundColor="white">
  6.  
  7.     <mx:ApplicationControlBar dock="true">
  8.         <!-- Move the divider 20 pixels to the left for as long as the
  9.              Button control is pressed (autoRepeat=true). -->
  10.         <mx:Button label="x-=20"
  11.                 autoRepeat="true"
  12.                 buttonDown="hdivbox.moveDivider(0, -20);" />
  13.         <!-- Move the divider 20 pixels to the right for as long as the
  14.              Button control is pressed (autoRepeat=true). -->
  15.         <mx:Button label="x+=20"
  16.                 autoRepeat="true"
  17.                 buttonDown="hdivbox.moveDivider(0, 20);" />
  18.  
  19.         <mx:Spacer width="50" />
  20.  
  21.         <!-- Move the divider to 100 pixels from the left. -->
  22.         <mx:Button label="x=100"
  23.                 click="hdivbox.getDividerAt(0).x = 100;" />
  24.         <!-- Move the divider to 420 pixels from the left. -->
  25.         <mx:Button label="x=420"
  26.                 click="hdivbox.getDividerAt(0).x = 420;" />
  27.     </mx:ApplicationControlBar>
  28.  
  29.     <mx:HDividedBox id="hdivbox" width="100%" height="100%">
  30.         <mx:VBox backgroundColor="haloGreen" width="100%" height="100%">
  31.             <!-- children -->
  32.         </mx:VBox>
  33.         <mx:VBox backgroundColor="haloBlue" width="100%" height="100%">
  34.             <!-- children -->
  35.         </mx:VBox>
  36.     </mx:HDividedBox>
  37.  
  38. </mx:Application>
代码:Peter deHaan 翻译/整理/编译:中文Flex例子

Topics: HDividedBox | No Comments » | 1,370 views Tags: , , ,

Search Posts