您可以使用 JFeinstein 滑动菜单轻松添加任意数量的菜单级别。想法是使用滑动菜单作为主滑动菜单的左或右滑动视图等。添加了带有注释和输出的 2 级菜单的完整代码,以使事情更加清晰。
public class MainActivity extends SlidingFragmentActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// dummy views - content view
TextView content = new TextView(this);
content.setBackgroundColor(Color.WHITE);
content.setText("content");
// Menu view
TextView menu = new TextView(this);
menu.setBackgroundColor(Color.GREEN);
menu.setText("menu");
// 2nd level menu view
TextView subMenu = new TextView(this);
subMenu.setBackgroundColor(Color.LTGRAY);
subMenu.setText("submenu");
//configure sliding menu
SlidingMenu sm = getSlidingMenu();
sm.setMode(SlidingMenu.SLIDING_WINDOW);
sm.setTouchModeAbove(SlidingMenu.TOUCHMODE_FULLSCREEN);
sm.setBehindOffset(80);
sm.setBehindScrollScale(0.25f);
sm.setFadeDegree(0.25f);
//Another sliding menu - for 2nd level or sub menu
SlidingMenu leftSlidingView = new SlidingMenu(this);
leftSlidingView.setMode(SlidingMenu.SLIDING_WINDOW);
leftSlidingView.setTouchModeAbove(SlidingMenu.TOUCHMODE_FULLSCREEN);
leftSlidingView.setBehindOffset(80);
leftSlidingView.setBehindScrollScale(0.25f);
leftSlidingView.setFadeDegree(0.25f);
//==== Required instruments has been created ;) lets put them at right places
// setting menu and sub-menu view
leftSlidingView.setContent(menu); // at center of left sliding view
leftSlidingView.setMenu(subMenu); // at left of left sliding view
//set content view
setContentView(content); // at center of main sliding view
// finally, set leftSlidingView as behind content view of main view
setBehindContentView(leftSlidingView); // at left of main sliding view
}
}
这是输出:
注意:您需要将 JFeinstein 滑动菜单作为库导入并从 SlidingFragmentActivity 扩展您的活动。