user5881997
user5881997

Reputation: 229

Navigation view has more gap before first menu

I have created navigation drawer. I tried to create drawer and navigation view below the toolbar. But It shows more gap before first menu of navigation view. I want to reduce this gap. Any solution for this?

enter image description here

Layout main:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    xmlns:tools="http://schemas.android.com/tools"
    android:fitsSystemWindows="true"
    android:orientation="vertical">

    <android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:background="?attr/colorPrimary"/>

    <android.support.v4.widget.DrawerLayout
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:id="@+id/nav_drawer"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fitsSystemWindows="true">


    <!-- Real content goes here -->
        <FrameLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:id="@+id/nav_contentframe"
            android:background="@android:color/background_light"
            android:layout_below="@+id/toolbar"/>

        <!-- The navigation drawer -->
        <android.support.design.widget.NavigationView
            android:id="@+id/nav_view"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:layout_gravity="start"
            android:fitsSystemWindows="false"
            app:menu="@menu/nav_menu"
            android:background="@android:color/background_light"
            android:gravity="top"
            android:foregroundGravity="top"
            android:weightSum="0" />


    </android.support.v4.widget.DrawerLayout>
</LinearLayout>

How to solve this?

Thank you.

Upvotes: 0

Views: 1214

Answers (2)

srinivas
srinivas

Reputation: 72

Use header attribute for the Navigation view and set a layout for the header.Now you can adjust accordingly in the headerlayout itself.

Upvotes: 0

Sally
Sally

Reputation: 950

Try to add -PaddingTopValue to NavigationMenuView not to navigationView.

        navigationView = (NavigationView) findViewById(R.id.nav_view);
//        navigationView.setPadding(0, -10, 0, 0); // not work
        ((NavigationMenuView)navigationView.getChildAt(0)).setPadding(0, -10, 0, 0);

Upvotes: 4

Related Questions