gpt4 book ai didi

android - 无法删除 nav_host_fragment 顶部的空间

转载 作者:行者123 更新时间:2023-12-03 13:24:30 32 4
gpt4 key购买 nike

我刚刚实现了一个底部导航(AS的默认-文件->新建-> Activity ->底部导航 Activity )一切都很好,除了nav_host_fragment顶部的空间。 .

wrong space

由于它是在 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" />

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

最佳答案

删除 此行来自您的相对布局 .

android:paddingTop="?attr/actionBarSize"

关于android - 无法删除 nav_host_fragment 顶部的空间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57628238/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com