[UI]抽屜菜單DrawerLayout分析

[UI]抽屜菜單DrawerLayout分析
本文轉載於:http://www.cnblogs.com/avenwu/a
[UI]抽屜菜單DrawerLayout分析(一)
2015-01-05 15:47 862人閱讀 評論(0) 收藏 舉報
目錄(?)[+]
本文轉載於:http://www.cnblogs.com/avenwu/archive/2014/04/16/3669367.html
側拉菜單作爲常見的導航交互控件,最開始在沒有沒有android官方控件時,很多時候都是使用開源的SlidingMenu,一直沒機會分析側拉菜單的實現機理,本文將分析android.support.v4.widget.DrawerLayout的使用及實現。

Device 2014 04 16 191818

官方介紹

DrawerLayout acts as a top-level container for window content that allows for interactive “drawer” views to be pulled out from the edge of the window.

Drawer positioning and layout is controlled using the android:layout_gravity attribute on child views corresponding to which side of the view you want the drawer to emerge from: left or right. (Or start/end on platform versions that support layout direction.)

To use a DrawerLayout, position your primary content view as the first child with a width and height of match_parent. Add drawers as child views after the main content view and set the layout_gravity appropriately. Drawers commonly use match_parent for height with a fixed width.

DrawerLayout.DrawerListener can be used to monitor the state and motion of drawer views. Avoid performing expensive operations such as layout during animation as it can cause stuttering; try to perform expensive operations during the STATE_IDLE state. DrawerLayout.SimpleDrawerListener offers default/no-op implementations of each callback method.

As per the Android Design guide, any drawers positioned to the left/start should always contain content for navigating around the application, whereas any drawers positioned to the right/end should always contain actions to take on the current content. This preserves the same navigation left, actions right structure present in the Action Bar and elsewhere

DrawerLayout直譯的事抽屜佈局的意思,作爲視窗內的頂層容器,它允許用戶通過抽屜式的推拉操作,從而把視圖視窗外邊緣拉到屏幕內,如右圖:

抽屜菜單的擺放和佈局通過android:layout_gravity屬性來控制,可選值爲left、right或start、end。通過xml來佈局的話,需要把DrawerLayout作爲父容器,組界面佈局作爲其第一個子節點,抽屜佈局則緊隨其後作爲第二個子節點,這樣就做就已經把內容展示區和抽屜菜單區獨立開來,只需要分別非兩個區域設置內容即可。android提供了一些實用的監聽器,重載相關的回調方法可以在菜單的交互過程中書寫邏輯業務。下面是一個demo佈局:

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章