代码:
MainActivity.java
package com.xiaofei.app.slidingmenu; import android.app.Activity; import android.graphics.Color; 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); //创建侧滑菜单 SlidingMenu menu=new SlidingMenu(this); // menu.setMode(SlidingMenu.LEFT); menu.setMode(SlidingMenu.LEFT_RIGHT); menu.setTouchModeAbove(SlidingMenu.TOUCHMODE_FULLSCREEN); // menu.setBehindWidth(200); menu.setBehindOffsetRes(R.dimen.menu_offset);//设置相对屏幕的偏移量 menu.setBackgroundColor(Color.LTGRAY); menu.setFadeDegree(0.55f); menu.setMenu(R.layout.menu_layout); menu.setBehindScrollScale(0.0f); menu.setSecondaryMenu(R.layout.menu_layout2); menu.attachToActivity(this,SlidingMenu.SLIDING_CONTENT); } }
activity_main.xml
menu_layout.xml
menu_layout2.xml
MainActivity2.xml
package com.xiaofei.app.slidingmenu; import android.graphics.Color; import android.os.Bundle; import com.jeremyfeinstein.slidingmenu.lib.SlidingMenu; import com.jeremyfeinstein.slidingmenu.lib.app.SlidingListActivity; public class MainActivity2 extends SlidingListActivity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main2); setBehindContentView(R.layout.menu_layout); //创建侧滑菜单 SlidingMenu menu = getSlidingMenu(); menu.setMode(SlidingMenu.LEFT); menu.setTouchModeAbove(SlidingMenu.TOUCHMODE_FULLSCREEN); // menu.setBehindWidth(200); menu.setBehindOffsetRes(R.dimen.menu_offset);//设置相对屏幕的偏移量 menu.setBackgroundColor(Color.LTGRAY); menu.setFadeDegree(0.55f); menu.setBehindScrollScale(0.0f); //menu.setMenu(R.layout.menu_layout); // menu.attachToActivity(this,SlidingMenu.SLIDING_CONTENT); } }
activity_main2.xml
MainActivity3.xml
package com.xiaofei.app.slidingmenu; import android.app.Activity; import android.os.Bundle; public class MainActivity3 extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main3); } }
activity_main3.xml
AndroidManifest.xml