Android - Sliding menu with sub menu

自古美人都是妖i 提交于 2019-12-03 06:13:55

Check out the Sliding Panel component a widget enabling multiple overlaid views with sliding interaction for showing multiple depth data in one screen display effectively.

It also provide the demo of referenced implementation you can also check it.

Thanks.

You can easily add as many menu levels as you desired using JFeinstein sliding menu. The idea is to use sliding menu as left or right sliding view of main sliding menu and so on. Complete code of 2 level menu with comments and output is added to make things more clear.

 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

    }
}

Here is the output:

Note: You need to import JFeinstein sliding menu as library and extend your activity from SlidingFragmentActivity.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!