Android drawer effect navigation menu implementation code example
After reading many applications, I think this kind of side sliding drawer effect menu is very good.
You don't have to switch to another page or press the hardware button of the menu. Click a button directly on the interface, and the menu will slide out, and you feel that you can put a lot of things.
About implementation, I searched for the following two types:
1. Use slidingdrawer: http://developer.android.com/reference/android/widget/SlidingDrawer.html
But I don't know why this class is officially not recommended to continue to use: deprecated since API level 17
2. Use drawerlayout: http://developer.android.com/reference/android/support/v4/widget/DrawerLayout.html
Here: http://developer.android.com/training/implementing-navigation/nav-drawer.html
Library reference
First, the drawerlayout class is in the support library. You need to add the android-support-v4.jar package.
Then import android.support.v4.widget.drawerlayout in front of the program;
If this class cannot be found, first update the Android support library with the SDK manager, then find android-support-v4.jar under the Android SDK \ extras \ Android \ support \ V4 path, copy it to the LIBS path of the project, and add it to build path
Code 1
Layout:
The first child element of drawerlayout is the main content, that is, the layout displayed when the drawer is not opened. A FrameLayout is adopted here, and nothing is put in it.
The second child element of drawerlayout is the contents in the drawer, that is, the drawer layout. Here, a listview is used.
Main activities (extracted from official instances):
What is more tangled is that an API of level 11 is used, so the minsdkversion is limited and cannot be too low.
Image resources are available for download on the Android official website.
After the program runs, the effect is as follows:
Before opening the drawer:
After opening the drawer:
Code 2
Today, I looked at the drawerlayout class and found that there are many methods that can be used directly.
Try again. In fact, it doesn't need to be so troublesome. Just define a button to control the opening of the drawer:
Layout:
Main code:
The above is the whole content of this article. I hope it will be helpful to your study, and I hope you can support programming tips.