Implementing Gmail Tablet like Navigation Drawer

后端 未结 2 1537
清歌不尽
清歌不尽 2021-01-30 15:13

I was looking into the tablet design of Gmail application. In that Navigation Drawer implementation is different from others. I have attached image for your referen

2条回答
  •  我在风中等你
    2021-01-30 15:40

    You can use a SlidingPaneLayout with a margin on the main pane and custom listener for the cross fading.

    
      
      
      
      
      
    
    

    Subclass SlidingPaneLayout and find the partial and full panes in onFinishInflate:

    protected void onFinishInflate() {
      super.onFinishInflate();
    
      if (getChildCount() < 1) {
        return;
      }
    
      View panel = getChildAt(0);
      if (!(panel instanceof ViewGroup)) {
        return;
      }
    
      ViewGroup viewGroup = (ViewGroup) panel;
      if (viewGroup.getChildCount() != 2) {
        return;
      }
      fullView = viewGroup.getChildAt(0);
      partialView = viewGroup.getChildAt(1);
    
      super.setPanelSlideListener(crossFadeListener);
    }
    

    Change the alpha of the full pane and partial pane with a listener:

    private SimplePanelSlideListener crossFadeListener 
        = new SimplePanelSlideListener() {
      public void onPanelSlide(View panel, float slideOffset) {
        super.onPanelSlide(panel, slideOffset);
        if (partialView == null || fullView == null) {
          return;
        }
    
        partialView.setVisibility(isOpen() ? View.GONE : VISIBLE);
        partialView.setAlpha(1 - slideOffset);
        fullView.setAlpha(slideOffset);
      }
    };
    

    Also, hide the partial pane when the layout is opened.

    protected void onLayout(
        boolean changed, int l, int t, int r, int b) {
      super.onLayout(changed, l, t, r, b);
    
      if (partialView != null) {
        partialView.setVisibility(isOpen() ? View.GONE : VISIBLE);
      }
    }
    

    More info: http://blog.sqisland.com/2015/01/partial-slidingpanelayout.html

提交回复
热议问题