Flex中如何通过[aptly named] percentWidth和percentHeight属性设置一个按钮(Button)的最大宽度和高度的例子
By Minidxer | September 25, 2008
接下来的例子演示了Flex中如何通过[aptly named] percentWidth和percentHeight属性,设置一个按钮(Button)的最大宽度和高度。
让我们先来看一下Demo(可以右键View Source或点击这里察看源代码):
下面是完整代码(或点击这里察看):
Download: main.mxml
- <?xml version="1.0" encoding="utf-8"?>
- <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
- layout="vertical"
- verticalAlign="middle"
- backgroundColor="white">
- <mx:Script>
- <![CDATA[
- import mx.events.SliderEvent;
- private function wSlider_change(evt:SliderEvent):void {
- button.percentWidth = evt.value;
- button.label = "w:" + button.width +
- ", h:" + button.height;
- }
- private function hSlider_change(evt:SliderEvent):void {
- button.percentHeight = evt.value;
- button.label = "w:" + button.width +
- ", h:" + button.height;
- }
- ]]>
- </mx:Script>
- <mx:ApplicationControlBar dock="true">
- <mx:Label text="percentWidth:" />
- <mx:HSlider id="wSlider"
- liveDragging="true"
- showTrackHighlight="true"
- minimum="10"
- maximum="100"
- change="wSlider_change(event);"
- snapInterval="1"
- tickInterval="10"
- labels="[10%,100%]" />
- <mx:Spacer width="100%" />
- <mx:Label text="percentHeight:" />
- <mx:HSlider id="hSlider"
- liveDragging="true"
- showTrackHighlight="true"
- minimum="10"
- maximum="100"
- change="hSlider_change(event);"
- snapInterval="1"
- tickInterval="10"
- labels="[10%,100%]" />
- </mx:ApplicationControlBar>
- <mx:Button id="button" label="Button" />
- </mx:Application>
代码:Peter deHaan 翻译/整理/编译:中文Flex例子
Topics:
Button |
No Comments » |
Tags: Button, percentHeight, percentWidth