论坛首页 编程语言技术论坛

flex的box中button的布局动态控制

浏览 2035 次
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
作者 正文
   发表时间:2009-06-29  
同一个页面工具栏,要在不同的功能模块下显示不同的按钮,不能直接删除该空间,否则一些方法里用到这些控件,程序报错。但是需要根据模块功能动态隐藏一些,只用btntest1.visible=false,该控件所占的位置为一段空白,必须同时设置btntest1.includeInLayout=false,才能既隐藏控件又释放了其所占的空间。
如果用了box来布局所有功能按钮,作为一个工具栏,必须注意它的autoLayout="false" 会影响单独的btn 的隐藏并释放所占空间的功能,所以这个属性切忌不要false.
  我今天用单独的btn,都没有问题,就是放到box不行,后来发现是这个属性捣乱。

testbtn后自动隐藏test2并释放所占空间;但是testbtn1控制的box设置了autoLayout属性,test12所占空间没有释放!
示例:
           private function onclick():void
           {
           test2.includeInLayout=false;
           test3.visible=true;
           }
           private function onclick1():void
           {
           test12.includeInLayout=false;
           test13.visible=true;
           }
...
          <mx:Button id="testbtn" label="testbtn" width="80" click="onclick()" y="100">
          </mx:Button> 
          <mx:Button id="testbtn1" label="testbtn1" width="80" click="onclick1()" x="100" y="100">
          </mx:Button>    
        <mx:Box  y="120" height="35" width="100%" direction="horizontal" >
        <mx:Button id="test1" label="test1" width="100" height="30"  visible="true" toolTip="test1" />
        <mx:Button id="test2" label="test2" width="100" height="30"  visible="false" toolTip="test2" />
        <mx:Button id="test3" label="test3" width="100" height="30"  visible="false" toolTip="test3" />
        <mx:Button id="test4" label="test4" width="100" height="30"  visible="true" toolTip="test4" />

        <mx:ComboBox width="200">
       </mx:ComboBox>   
        </mx:Box>
         <mx:Box  y="180" height="35" width="100%" direction="horizontal"  horizontalGap="0" autoLayout="false">
        <mx:Button id="test11" label="test1" width="100"  height="30"   visible="true" />
        <mx:Button id="test12" label="test2" width="100"  height="30"  visible="false"  />
        <mx:Button id="test13" label="test3" width="100"  height="30"  visible="false"  />
        <mx:Button id="test14" label="test14" width="100"  height="30"  visible="true"  />

        <mx:ComboBox width="200">
       </mx:ComboBox>   
        </mx:Box>
...
论坛首页 编程语言技术版

跳转论坛:
Global site tag (gtag.js) - Google Analytics