On the day of the 2013 Google Io, the Android team updated the support library and added the Navigationdrawer (navigation menu).
1. Create Drawerlayout
Create Drawerlayout
In the interface that needs the drawer menu, use DrawerLayout as the interface root control. In Drawerlayout, the first view is the main content of the current interface, and the second and third view are the contents of the Drawer menu. If the current interface requires only one drawer menu, the third view can be omitted.
In the following example, Drawerlayout contains two view, the first framelayout is the main content display area of the current interface, and the second ListView is the contents of a drawer menu.
<Android.support.v4.widget.DrawerLayoutxmlns:android= "Http://schemas.android.com/apk/res/android"Android:id= "@+id/drawer_layout"Android:layout_width= "Match_parent"Android:layout_height= "Match_parent"> <!--The main content view. - <FramelayoutAndroid:id= "@+id/content_frame"Android:layout_width= "Match_parent"Android:layout_height= "Match_parent" /> <!--The navigation drawer. - <ListViewAndroid:id= "@+id/left_drawer"Android:layout_width= "240DP"Android:layout_height= "Match_parent"android:layout_gravity= "Start"Android:choicemode= "Singlechoice"Android:divider= "@android: Color/transparent"Android:dividerheight= "0DP"Android:background= "#111"/></Android.support.v4.widget.DrawerLayout>
- The view (above) that displays the main interface content of the interface
FrameLayout must be the first child view of Drawerlayout, because the view order in the XML layout file is the z-ordering order in the Android system. The drawer must appear on top of the content.
- The view width and height of the display interface content is set to the same as the parent view, because the interface content represents the entire interface UI when the drawer menu is not visible.
- The drawer menu (above
ListView ) must use the Android:layout_gravity property to set the horizontal gravity value . If you want to support Right-to-left (RTL, right-to-left reading) language "start" instead of (when the RTL language is running, the menu appears on the right).
- The width of the drawer menu is the same as the height of the
dp parent view. The width of the drawer menu should be no more than 320DP, so that users can see some content interface when the menu is open.
.
Usage of navigationdrawer (navigation drawer)