我在寫一個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; }