简体   繁体   English

Adobe AIR Flex:动态改变 VGroup 的宽度

[英]Adobe AIR Flex : Dynamically change the width of VGroup

We have a Adobe AIR desktop application.我们有一个 Adobe AIR 桌面应用程序。 In the window there is a topbar with some buttons.在 window 中有一个带有一些按钮的顶栏。 The central button opens a dropdown popup always at the horizontal center of the screen.中央按钮始终在屏幕的水平中心打开一个下拉弹出窗口。 Previously there was no scrolbar and the topbar and the popup was always aligned horizontally.以前没有滚动条,顶部栏和弹出窗口始终水平对齐。 But now we have introduced horizontal and vertical scrollbars and hence when the window is resized, the topbar is not at the center of the active window and hence it's not aligned with the popup.但是现在我们引入了水平和垂直滚动条,因此当 window 调整大小时,顶部栏不在活动 window 的中心,因此它与弹出窗口不对齐。

Please check the pictures.请检查图片。 The topbar -顶栏——

在此处输入图像描述

The popup -弹出窗口 -

在此处输入图像描述

If the window is maximized in the horizontal side, then the topbar and the popup is aligned.如果 window 在水平侧最大化,则顶部栏和弹出窗口对齐。

Now the mxml code -现在是 mxml 代码 -

public function showMainMenu():void
        {
            log.debug("Menu button clicked.");
            if(animatingMenu)
            {
                log.debug("Suppressing showing of menu. Animation already in progress.");
                return;
            }
            animatingMenu = true;
            menuButton.visible = true;
            mainMenu.visible = true;
            PopUpManager.addPopUp(mainMenu, FlexGlobals.topLevelApplication as DisplayObject, true);
            PopUpManager.centerPopUp(mainMenu);
            mainMenu.y = -mainMenu.height + menuButton.height;
            mainMenu.refresh();
            showMenuEffect.play();
            menuButton.visible = false; 
        }


<fx:Declarations>
    <menu:MainMenu id="mainMenu"/>
    <s:Move id="showMenuEffect" target="{mainMenu}" yFrom="{-mainMenu.height+menuButton.height}" yTo="-5" effectEnd="menuShowed(event)" duration="1200"/>
    <s:Move id="hideMenuEffect" target="{mainMenu}" yFrom="-5" yTo="{-mainMenu.height+menuButton.height}" effectEnd="menuHided(event)" duration="600"/>
</fx:Declarations>

<s:HGroup width="100%">
    <s:VGroup horizontalAlign="center" width="100%" paddingLeft="{this.width / 2 - menuButton.width / 2}">
        <s:Button id="menuButton" automationName="menuButtonShow" click="showMainMenu()" styleName="mainMenuButton" height="40" width="200"/>
    </s:VGroup>
    
    <s:HGroup horizontalAlign="right" width="100%" paddingRight="48" paddingTop="10">
        <desktop:LocaleSelector id="localeSelector"/>
        <desktop:ButtonCorner id="buttonCorner"/>
    </s:HGroup>
    
    <s:VGroup paddingRight="24" paddingTop="25" horizontalAlign="right">
        <s:Button id="closeScreenButton" visible="false" styleName="closeScreenButton" width="29" height="35"/>
    </s:VGroup>     
</s:HGroup>

What should be changed?应该改变什么? How I can position the topbar always at the center of the screen.我怎么能 position 顶部栏总是在屏幕的中心。 Should I create css file to handle this case?我应该创建 css 文件来处理这种情况吗?

This is the default behavior.这是默认行为。 When you show a popup, you tell it where to be places in.y and.x.当您显示一个弹出窗口时,您会告诉它在.y 和.x 中的位置。 When you scroll or resize you effectively change the "center" of the window, but you never inform it that it has changed.当您滚动或调整大小时,您实际上更改了 window 的“中心”,但您从未通知它它已更改。

What I would try is adding a listener for window resize and onChange re-center the popup.我会尝试为 window 调整大小和onChange重新居中弹出窗口添加一个侦听器。

Sample Code (this is not tested but should work):示例代码(未经测试,但应该可以工作):

var widthWatch:ChangeWatcher = ChangeWatcher.watch(this, 'widht', resizeHandler);
private var resizeExecuting:Boolean = false;

//this should run as soon as your app does (in most cases I do that in creationComplete or initialize())
private function onCreationComplete(event:Event):void
{
    widthWatch = ChangeWatcher.watch(this,'width',onSizeChange); 
}
//this checks if the resize stopped before actually moving the popup. Alternatively you can move your popup.center code here
private function onSizeChange(event:Event):void
{
    if(!resizeExecuting)
    callLater(handleResize);
    resizeExecuting = true;
}
  
private function handleResize():void
{
    PopUpManager.centerPopUp(mainMenu);
    resizeExecuting = false;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM