[英]Adobe AIR Flex : Dynamically change the width of VGroup
我們有一個 Adobe AIR 桌面應用程序。 在 window 中有一個帶有一些按鈕的頂欄。 中央按鈕始終在屏幕的水平中心打開一個下拉彈出窗口。 以前沒有滾動條,頂部欄和彈出窗口始終水平對齊。 但是現在我們引入了水平和垂直滾動條,因此當 window 調整大小時,頂部欄不在活動 window 的中心,因此它與彈出窗口不對齊。
請檢查圖片。 頂欄——
彈出窗口 -
如果 window 在水平側最大化,則頂部欄和彈出窗口對齊。
現在是 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>
應該改變什么? 我怎么能 position 頂部欄總是在屏幕的中心。 我應該創建 css 文件來處理這種情況嗎?
這是默認行為。 當您顯示一個彈出窗口時,您會告訴它在.y 和.x 中的位置。 當您滾動或調整大小時,您實際上更改了 window 的“中心”,但您從未通知它它已更改。
我會嘗試為 window 調整大小和onChange
重新居中彈出窗口添加一個偵聽器。
示例代碼(未經測試,但應該可以工作):
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.