小编Igo*_*urt的帖子

无法删除nav_host_fragment顶部的空间

我刚刚实现了底部导航(AS的默认设置-文件->新建->活动->底部导航活动),除了顶部的空格外,其他都不错nav_host_fragment

错误的空间

由于它是在ConstraintLayout中生成的,因此我尝试清除约束并使用设置最高约束parent,将其设置margin为'0dp'并设置heightmatch_constraint

我未能成功删除约束,并反复尝试。

我用过Clean Project

我改为RelativeLayout并设置如下参数:

 <fragment
            android:id="@+id/nav_host_fragment"
            android:name="androidx.navigation.fragment.NavHostFragment"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_alignParentTop="true"
            android:layout_above="@+id/nav_view"
            app:defaultNavHost="true"
            app:navGraph="@navigation/mobile_navigation" />
Run Code Online (Sandbox Code Playgroud)

但是nav_host_fragment顶部之间的空间仍然存在。

这是lyout文件:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        xmlns:tools="http://schemas.android.com/tools"
        android:id="@+id/container"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:paddingTop="?attr/actionBarSize">

    <com.google.android.material.bottomnavigation.BottomNavigationView
            android:id="@+id/nav_view"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:background="?android:attr/windowBackground"
            app:menu="@menu/bottom_nav_menu" />

    <fragment
            android:id="@+id/nav_host_fragment"
            android:name="androidx.navigation.fragment.NavHostFragment"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_alignParentTop="true"
            android:layout_above="@+id/nav_view"
            app:defaultNavHost="true"
            app:navGraph="@navigation/mobile_navigation" />

</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)

android android-fragments bottomnavigationview

3
推荐指数
1
解决办法
206
查看次数