项目地址:
https://github.com/gokhanakkurt/android-menudrawer
https://github.com/jfeinstein10/SlidingMenu
android-menudrawer用法:
protected MenuDrawer mDrawer; /**传入当前activity的布局文件*/ protected void initMenu(int layoutmain) { mDrawer = MenuDrawer.attach(this, MenuDrawer.MENU_DRAG_CONTENT,Position.RIGHT); mDrawer.setTouchMode(MenuDrawer.TOUCH_MODE_FULLSCREEN); mDrawer.setContentView(layoutmain); mDrawer.setMenuView(R.layout.menu_sample); mDrawer.setDropShadow(R.drawable.shadow); mDrawer.setDropShadowSize((int) getResources().getDimension(R.dimen.shadow_width)); mDrawer.setMaxAnimationDuration(3000); mDrawer.setHardwareLayerEnabled(false); mDrawer.setMenuSize((int) getResources().getDimension(R.dimen.slidingmenu_offset)); } mDrawer.toggleMenu(); 自动判断是打开还是关闭状态 在activity onCreate方法最后面加入 mDrawer.peekDrawer(); 在viewpager下应用 OnPageChangeListener事件的onPageSelected方法下加入 mDrawer.setTouchMode(index == fragments.size()-1 ? MenuDrawer.TOUCH_MODE_FULLSCREEN : MenuDrawer.TOUCH_MODE_NONE);
SlidingMenu用法
SlidingMenu menu = new SlidingMenu(this); menu.setMode(SlidingMenu.RIGHT); menu.setTouchModeAbove(SlidingMenu.TOUCHMODE_FULLSCREEN); menu.setShadowWidthRes(R.dimen.shadow_width); menu.setShadowDrawable(R.drawable.shadow); menu.setBehindOffsetRes(R.dimen.slidingmenu_offset); menu.setFadeDegree(0.35f); menu.attachToActivity(this, SlidingMenu.SLIDING_CONTENT); menu.setMenu(R.layout.menu_sample);
menu.toggle(); 方法自动判断是打开还是关闭状态
在viewpager控件下应用
在onPageSelected方法中
menu.setTouchModeAbove(index == fragments.size()-1
? SlidingMenu.TOUCHMODE_FULLSCREEN
: SlidingMenu.TOUCHMODE_NONE); 因为我是在右边显示所以总数减1
android-menudrawer 和SlidingMenu 用法
时间: 2024-11-02 20:32:44