package animtest.com.example.e531.slidingmenu_demo;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.os.Bundle;
import com.jeremyfeinstein.slidingmenu.lib.SlidingMenu;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
initSlidingMenu();
}
}
private void initSlidingMenu() {
// 设置SlidingMenu
SlidingMenu menu = new SlidingMenu(this);
//设置侧滑方式为Left:左侧 RIGHT:右侧 LEFT_RIGHT:两侧都可以
menu.setMode(SlidingMenu.LEFT);
// 设置SlidingMenu
SlidingMenu menu = new SlidingMenu(this);
//设置侧滑方式为Left:左侧 RIGHT:右侧 LEFT_RIGHT:两侧都可以
menu.setMode(SlidingMenu.LEFT);
/**
* 设置拖拽模式
* SlidingMenu.TOUCHMODE_FULLSCREEN:全屏触摸有效
* SlidingMenu.TOUCHMODE_MARGIN:拖拽边缘有效
* SlidingMenu.TOUCHMODE_NONE:不响应拖拽事件
*/
menu.setTouchModeAbove(SlidingMenu.TOUCHMODE_FULLSCREEN);
//设置阴影的宽度
menu.setShadowWidthRes(R.dimen.shadow_width);
//设置阴影的图片
menu.setShadowDrawable(R.drawable.shadow);
* 设置拖拽模式
* SlidingMenu.TOUCHMODE_FULLSCREEN:全屏触摸有效
* SlidingMenu.TOUCHMODE_MARGIN:拖拽边缘有效
* SlidingMenu.TOUCHMODE_NONE:不响应拖拽事件
*/
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);
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);
}
}
---xml布局
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#f00">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#f00">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="这是菜单。。。"
android:id="@+id/textView" />
</LinearLayout>