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