一个简单的侧滑菜单SimpleSlidingMenu

概述

一个简单的Android侧滑菜单,支持left, right,left_right三种菜单模式,支持edge,all两种滑动模式,支持设置菜单的宽度,支持滑动动画

效果如下

每个Fragment里面是一个RecyclerView,解决了滑动冲突问题,包含滑动动画

这里写图片描述

使用方式

private SlidingMenuLayout mSlideMenuLayout;

 @Override protected void onCreate(Bundle savedInstanceState) {
   super.onCreate(savedInstanceState);
   mSlideMenuLayout = new SlidingMenuLayout(this);
   setContentView(mSlideMenuLayout);
   initSlideMenuLayout();
 }

 private void initSlideMenuLayout() {
       getSupportFragmentManager().beginTransaction()
               .replace(SlidingMenuLayout.LEFT_TAG, ItemFragment.newInstance(1))
               .commit();
       getSupportFragmentManager().beginTransaction()
               .replace(SlidingMenuLayout.MIDDLE_TAG, ItemFragment.newInstance(1))
               .commit();
       getSupportFragmentManager().beginTransaction()
               .replace(SlidingMenuLayout.RIGHT_TAG, ItemFragment.newInstance(1))
               .commit();
       mSlideMenuLayout.setBackgroundColor(Color.parseColor("#4876FF"));
       mSlideMenuLayout.setMenuMode(SlidingMenuLayout.MenuMode.LEFT_RIGHT);
       mSlideMenuLayout.setSlidingMode(SlidingMenuLayout.SlidingMode.ALL);
       mSlideMenuLayout.setSlideEnable(true);
       mSlideMenuLayout.setMenuContentWidthRation(0.75f);
 }
  • 把SlidingMenuLayout作为根布局
  • 左侧,中间,以及右侧菜单布局都会有一个tag,通过给每一个布局设置一个fragment即可!
  • 具体参考代码中的:MainActivity.java

关于滑动动画

滑动动画主要是给SlideMenuLayout设置IOnMenuOpenListener接口,在接口里面对菜单以及中间视图进行一些缩放、透明度以及平移操作,从而达到动画效果,如下所示:

mSlideMenuLayout.setOnMenuOpenListener(new SlidingMenuLayout.IOnMenuOpenListener() {
           @Override
           public void menuOpen(View menuView, View middleView, float openPercent, boolean isLeftMenu) {
               float menuScale = (float) (0.8 + 0.2 * openPercent);//0.8到1
               float contentScale = (float) (1 - 0.2 * openPercent);//1到0.8
               float translationXScale = 0;
               if (isLeftMenu) {
                   translationXScale = (1 - openPercent) * 0.6f;//范围是0.6到0
               } else {
                   translationXScale = -(1 - openPercent) * 0.6f;//范围是-0.6到0
               }
               menuView.setScaleX(menuScale);
               menuView.setScaleY(menuScale);
               menuView.setAlpha(openPercent);
               menuView.setTranslationX(menuView.getWidth() * translationXScale);
               middleView.setScaleX(contentScale);
               middleView.setScaleY(contentScale);
           }
       });

代码地址:https://github.com/EasyLiu-Ly/SimpleSlidingMenu.git

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值