flex纵向滚动条出现后,横向滚动条自动出现(转)

我在写一个module,放了很多组件,发现只要出现纵向滚动条之后,横向的也会出现,怎么也去不掉,苦恼了很久,终于在网上找了解决办法,

为了让更多的朋友看到,便转到自己的博客中



我这篇文章的来源

http://edu.gamfe.com/tutor/d/24844.html



当你把容器的宽度调为100%后 ,verticalScrollbarPolicy 用默认的auto。这是如果你缩放窗口会出现滚动条,但问题这是就出现了,只要出现了垂直滚动条,水平滚动条就是被迫出现。

<?xml version="1.0" encoding="utf-8"?>  

<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" xmlns:local="*">  

    <mx:Canvas width="100%" height="700"/>  

</mx:Application>  


这是是由于flex在计算前面的百分比时,把垂直滚动条的宽度也算上了,我一开始以为是flex的bug。使其他的官方文档中写了一句很华丽的话。


"Flex considers scroll bars in its sizing calculations only if you explicitly set the scroll policy to ScrollPolicy.ON. So, if you use an auto scroll policy (the default), the scroll bar overlaps the buttons. To prevent this behavior, you can set the height property for the HBox container or allow the HBox container to resize by setting a percentage-based width. Remember that changing the height of the HBox container causes other components in your application to move and resize according to their own sizing rules."


-- From Sizing Components in the Flex 3 help, under "Using Scroll bars"


就这样回避了这个问题。但有个办法你可以解决这个问题,重载validateSize方法


// In your Application ,module or wherever you need this workaround.   

override public function validateSize(recursive:Boolean = false):void {   

    super.validateSize(recursive);   

    if (!initialized) 
	return;   

    if (height < measuredHeight) 
	verticalScrollPolicy = ScrollPolicy.ON;   
    else 
	verticalScrollPolicy = ScrollPolicy.OFF;   

} 


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值