在github.com网站搜索slidingmenu后https://github.com/jfeinstein10/SlidingMenu

下载demo,导入library到你的项目中,添加到你项目的依赖中使用:

package com.loaderman.slidingmenudemo;

import android.app.Activity;
import android.os.Bundle; import com.jeremyfeinstein.slidingmenu.lib.SlidingMenu; public class MainActivity extends Activity { @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// configure the SlidingMenu
SlidingMenu menu = new SlidingMenu(this);
menu.setMode(SlidingMenu.LEFT);
// 设置触摸屏幕的模式
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);
/**
* SLIDING_WINDOW will include the Title/ActionBar in the content
* section of the SlidingMenu, while SLIDING_CONTENT does not.
*/
//把滑动菜单添加进所有的Activity中,可选值SLIDING_CONTENT , SLIDING_WINDOW
menu.attachToActivity(this, SlidingMenu.SLIDING_CONTENT);
//为侧滑菜单设置布局
menu.setMenu(R.layout.leftmenu);
}
}

activity_main.xml

<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:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity"> <TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="主界面"
/> </RelativeLayout>

drawable下创建shadow.xml

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" > <gradient
android:endColor="#33000000"
android:centerColor="#11000000"
android:startColor="#00000000" /> </shape>

侧边栏布局leftmenu.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" > <TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:text="Hello Sliding Menu!" /> </LinearLayout>

dimens.xml

   <dimen name="slidingmenu_offset">80dp</dimen>
<dimen name="shadow_width">15dp</dimen>

实现效果:

最新文章

  1. caffe中accuracy和loss用python从log日志里面获取
  2. js中json对象的深拷贝
  3. Linq实例
  4. Android 微信分享图文资料
  5. Ant、Maven、Gradle
  6. Android 设置控件可见与不可见
  7. 更改JENKINS主目录
  8. ManagerDay-2
  9. Unix/Linux环境C编程入门教程(22) C/C++如何获取程序的运行时间
  10. Codeforces Round #254 (Div. 1)-A,B
  11. Linux 7.2 + LAMP + Nagios-4.2.4 + 简单部署监控项
  12. input解决浏览器记住密码问题
  13. css3中空格和&gt;的区别
  14. 【Zookeeper】Zookeeper安装配置
  15. 原生js怎样获取后台端口数据
  16. NEO从入门到开窗(1) - 一个智能合约的诞生
  17. 【PYTHON】三级菜单
  18. python类库numpy中常见函数的用法
  19. bzoj3758. 数数
  20. iOS - 指定UIView的某几个角为圆角

热门文章

  1. 目标 - 在虚拟机CentOS7中无图形界面安装Oracle11G R2版本
  2. strings、strconv:让你高效的处理字符串
  3. Java入门指南-03 操作符与表达式
  4. 常用数据存储格式之xml
  5. 【vuex状态管理】使用步骤
  6. 在vue移动端使用lib-flexible和px2remLoader适配屏幕
  7. Java注解demo
  8. 详解thinkphp+redis+队列的实现代码
  9. Android图像处理之图形特效处理
  10. Java GUI :Hello World