Android 抽屉效果的导航菜单实现
不用切换到另一个页面,也不用去按菜单的硬件按钮,直接在界面上一个按钮点击,菜
单就滑出来,而且感觉能放很多东西。
关于实现,搜索了一下,有如下两种:
1.用 SlidingDrawer:
http://developer.android.com/reference/android/widget/SlidingDrawer.html
但是不知道为什么这个类官方不建议再继续用了:
Deprecated since API level 17
2.用 DrawerLayout:
http://developer.android.com/reference/android/support/v4/widget/DrawerLayout.html
Guide 在这里:
http://developer.android.com/training/implementing-navigation/nav-drawer.html
库的引用 首先,DrawerLayout 这个类是在 Support Library 里的,需要加上 android-
support-v4.jar 这个包。
然后程序中用时在前面导入 import android.support.v4.widget.DrawerLayout;
如果找不到这个类,首先用 SDK Manager 更新一下 Android Support Library,然后在
Android SDK\extras\android\support\v4 路径下找到 android-support-v4.jar,复制到项目的 libs
路径,将其 Add to Build Path.
代码 1 布局:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<android.support.v4.widget.DrawerLayout
xmlns: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 -->
<!-- main content must be the first element of DrawerLayout because it will be drawn first
and drawer must be on top of it -->
<FrameLayout
android:id="@+id/content_frame"
找软件资料,就到一览软件文库