本文介绍了无法删除nav_host_fragment顶部的空间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚实现了底部导航(AS的默认设置-文件->新建->活动->底部导航活动),除了 nav_host_fragment

I just implemented a bottom navigation (AS's default - File -> New -> Activity -> Bottom Navigation Activity) Everything is fine except for a space on the top of the nav_host_fragment.

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

Since it was generated in a ConstraintLayout, I tried to clean the constraints and set the top constraint with parent, setting margin to '0dp' and set height to match_constraint.

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

I unsuccessfully deleted the constraints and tried over and over again.

我使用了清洁项目

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

I changed to RelativeLayout and set arguments like this:

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

但是 nav_host_fragment 和顶部之间的空间

这里是配置文件:

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


推荐答案

删除您的 相对布局

Remove this line from your Relative Layout.

android:paddingTop="?attr/actionBarSize"

这篇关于无法删除nav_host_fragment顶部的空间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-10 20:31