Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/date/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 导航视图在第一个菜单之前有更多间隙_Android_Android Layout_Navigation Drawer_Android Navigationview - Fatal编程技术网

Android 导航视图在第一个菜单之前有更多间隙

Android 导航视图在第一个菜单之前有更多间隙,android,android-layout,navigation-drawer,android-navigationview,Android,Android Layout,Navigation Drawer,Android Navigationview,我已经创建了导航抽屉。我尝试在工具栏下方创建抽屉和导航视图。但它在导航视图的第一个菜单之前显示了更多的间隙。我想缩小这个差距。有什么解决办法吗 主要布局: <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent"

我已经创建了导航抽屉。我尝试在工具栏下方创建抽屉和导航视图。但它在导航视图的第一个菜单之前显示了更多的间隙。我想缩小这个差距。有什么解决办法吗

主要布局:

<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>

如何解决这个问题


谢谢。

尝试将-PaddingTopValue添加到NavigationMenuView而不是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);

尝试将-PaddingTopValue添加到NavigationMenuView,而不是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);

使用导航视图的标题属性并设置标题布局。现在您可以在标题布局本身中进行相应调整。

使用导航视图的标题属性并设置标题布局。现在您可以在标题布局本身中进行相应调整