欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

根据屏幕分辨率动态调整组件大小

程序员文章站 2022-05-27 08:36:20
...
将代码写在组件的preInitialize事件监听器里面
简化案例如下:
		<s:HGroup id="leftContianer" width="70%" preinitialize="leftContianer_preinitializeHandler(event)">
		</s:HGroup>
		<s:HGroup id="rightSpacerContainer" width="30%" preinitialize="rightSpacerContainer_preinitializeHandler(event)"/>

	protected function leftContianer_preinitializeHandler(e:FlexEvent):void
	{
		var hg:HGroup=(e.currentTarget) as HGroup;
		if(hg!=null){
			if(Capabilities.screenResolutionX<=1024){
				hg.percentWidth=80;
			}else{
				hg.percentWidth=70;
			}
		}
		
	}
	
	protected function rightSpacerContainer_preinitializeHandler(e:FlexEvent):void
	{
		var hg:HGroup=(e.currentTarget) as HGroup;
		if(hg!=null){
			if(Capabilities.screenResolutionX<=1024){
				hg.percentWidth=20;
			}else{
				hg.percentWidth=30;
			}
		}
		
	}