Search code examples
androidnavigation-drawerandroid-navigationview

How to minimize NavigationView / NavigationDrawer?


I'm trying to minimize or collapse the NavigationView / NavigationDrawer when my app is running on tablets.

The result I want is the one used by GMail app, see screenshot below (you can see the desired layout collapsed on the left).

enter image description here

Does exists any method or a pattern to follow to achieve this?


Solution

  • After reading carefully this official NavigationDrawer guidelines, I found that my question used wrong keywords : it is called mini navigation drawer (that's why I edited my question first).

    So I was able to find an answer:

    1. Use third party library, which is proposed in this answer (yes, my question is a duplicate!);
    2. Develop your own solution, by following this sample; be aware that you have to add some fancy animation and other decoration in order to respect Material design guidelines.

    Any way, the trick is to simply add a margin left to the detail view (FrameLayout in this case), like this:

    <?xml version="1.0" encoding="utf-8"?>
    <android.support.v4.widget.SlidingPaneLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
    
        <!--Master fragment-->
        <fragment
            android:name=".MainFragment"
            android:layout_width="220dp"
            android:layout_height="match_parent"
            android:id="@+id/fragment_master">
        </fragment>
    
        <!--Detail layout -->
        <FrameLayout
            android:layout_width="1000dp"
            android:layout_height="match_parent"
            android:layout_marginLeft="56dp">
        </FrameLayout>
    </android.support.v4.widget.SlidingPaneLayout>