How to move main content with Drawer Layout left side

前端 未结 6 431
有刺的猬
有刺的猬 2020-11-30 17:04

Just checked how to make menu with DrawerLayout here. But left side menu is moving on the front of main content. How can I set it to menu and main content move side by side(

6条回答
  •  离开以前
    2020-11-30 17:40

    OP got the answer. But for someone else that wants that effect, can use SlidingPaneLayout. It's designed for this purpose.

    In XML file:

    
    
    
    
        
        
            
                
    
    
                
            
        
        
    
        
    
        
    
        
            
            
        
            
    

    There are two panes, right and left, stick together and thus move together. For me, the left pane is the main pane and the right is hidden with a toggle icon to display it. (A view with id appBarSearchIcon).

    Remember, there is one viewgroup named, SlidingPaneLayout that has just two children, The Left and The Right.

    And important part in the activity:

            slidingPaneLayout = (SlidingPaneLayout) findViewById(R.id.mainFrame);
    //        Sets a color for covering left pane(Main Pane)
            slidingPaneLayout.setSliderFadeColor(ContextCompat.getColor(context, R.color.searchPaneFadeColor));
    
    //        The listener for Opening the Right pane(Hidden pane)
            findViewById(R.id.appBarSearchIcon).setOnClickListener(new OnClickListener() {
                @Override
                public void onClick(View view){
                    slidingPaneLayout.openPane();
                }
            });
    

    Closing the right pane is done by the API, just like Navigation Drawer.

提交回复
热议问题