Flex - 手風琴控制元件



介紹

手風琴控制元件是一個導航容器,它包含一組子容器,但一次只有一個子容器可見。

類宣告

以下是mx.containers.Accordian類的宣告:

public class Accordion 
   extends Container
      implements IHistoryManagerClient, IFocusManagerComponent

公共屬性

序號 屬性和描述
1

headerRenderer : IFactory

用於建立每個子元素的導航按鈕的工廠。

2

historyManagementEnabled : Boolean

如果設定為 true,此屬性將在該手風琴容器內啟用歷史記錄管理。

3

resizeToContent : Boolean

如果設定為 true,此手風琴會自動調整為其當前子元素的大小。

4

selectedChild : INavigatorContent

對當前可見的子容器的引用。

5

selectedIndex : int

當前可見的子容器的從零開始的索引。

受保護的屬性

序號 屬性和描述
1

contentHeight : Number

[只讀] 內容顯示區域的高度(以畫素為單位)。

2

contentWidth : Number

[只讀] 內容顯示區域的寬度(以畫素為單位)。

公共方法

序號 方法和描述
1

Accordion()

建構函式。

2

getHeaderAt(index:int):Button

返回對子容器的導航按鈕的引用。

3

loadState(state:Object):void

載入此物件的狀態。

4

saveState():Object

儲存此物件的狀態。

事件

序號 事件和描述
1

change

當選定的子容器更改時分派。

繼承的方法

此類繼承自以下類:

  • mx.core.Container
  • mx.core.UIComponent
  • mx.core.FlexSprite
  • flash.display.Sprite
  • flash.display.DisplayObjectContainer
  • flash.display.InteractiveObject
  • flash.display.DisplayObject
  • flash.events.EventDispatcher
  • Object

Flex 手風琴控制元件示例

讓我們按照以下步驟來檢查在 Flex 應用程式中使用手風琴控制元件,方法是建立一個測試應用程式:

步驟 描述
1 在包com.tutorialspoint.client下建立一個名為HelloWorld的專案,如Flex - 建立應用程式章節中所述。
2 修改HelloWorld.mxml,如下所述。保持其餘檔案不變。
3 編譯並執行應用程式以確保業務邏輯按要求工作。

以下是修改後的 mxml 檔案src/com.tutorialspoint/HelloWorld.mxml的內容。

<?xml version = "1.0" encoding = "utf-8"?>
<s:Application xmlns:fx = "http://ns.adobe.com/mxml/2009"
   xmlns:s = "library://ns.adobe.com/flex/spark"
   xmlns:mx = "library://ns.adobe.com/flex/mx
   width = "100%" height = "100%" minWidth = "500" minHeight = "500">
   
   <fx:Style source = "/com/tutorialspoint/client/Style.css" />	   
   <s:BorderContainer width = "630" height = "480" id = "mainContainer" 
      styleName = "container">
      <s:VGroup width = "100%" height = "100%" gap = "50" 
         horizontalAlign = "center" verticalAlign = "middle">
         <s:Label id = "lblHeader" text = "Complex Controls Demonstration" 
            fontSize = "40" color = "0x777777" styleName = "heading" />
            
         <s:Panel id = "accordianPanel" title = "Using Accordian" 
            width = "500" height = "300" >
            <s:layout>
               <s:HorizontalLayout  gap = "10" verticalAlign = "middle" 
                  horizontalAlign = "center" />	
            </s:layout>				
               
            <mx:Accordion id = "accordion" width = "95%" height = "90%">
               <s:NavigatorContent label = "Section 1" width = "100%" 
                  height = "100%">
                  <s:VGroup verticalAlign = "middle" horizontalAlign = "center" 
                     width = "100%" height = "100%">
                     <s:Label text = "Contents for Section 1" />	
                  </s:VGroup>							
               </s:NavigatorContent>
                  
               <s:NavigatorContent label = "Section 2" width = "100%" 
                  height = "100%">
                  <s:VGroup verticalAlign = "middle" horizontalAlign = "center"
                     width = "100%" height = "100%">
                     <s:Label text = "Contents for Section 2" />	
                  </s:VGroup>							
               </s:NavigatorContent>
                  
               <s:NavigatorContent label = "Section 3" width = "100%" 
                  height = "100%">
                  <s:VGroup verticalAlign = "middle" horizontalAlign = "center" 
                     width = "100%" height = "100%">
                     <s:Label text = "Contents for Section 3" />	
                  </s:VGroup>							
               </s:NavigatorContent>
                  
               <s:NavigatorContent label = "Section 4" width = "100%" 
                  height = "100%">
                  <s:VGroup verticalAlign = "middle" horizontalAlign = "center" 
                     width = "100%" height = "100%">
                     <s:Label text = "Contents for Section 4" />	
                  </s:VGroup>							
               </s:NavigatorContent>
            </mx:Accordion>
         </s:Panel>
      </s:VGroup>	 
   </s:BorderContainer>	
</s:Application>

完成所有更改後,讓我們像在Flex - 建立應用程式章節中一樣,在普通模式下編譯並執行該應用程式。如果應用程式一切正常,它將產生以下結果:[ 線上嘗試 ]

Flex Accordian Control
flex_complex_controls.htm
廣告