我刚刚实现了底部导航(AS 的默认设置 - 文件 -> 新建 -> 活动 -> 底部导航活动)除了顶部的空格之外,一切都很好nav_host_fragment
.
由于它是在 ConstraintLayout 中生成的,我尝试清理约束并设置顶部约束parent
, 环境margin
为“0dp”并设置height
to match_constraint
.
我尝试了一遍又一遍,但没有成功删除约束。
I used 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>
Remove这行来自你的相对布局.
android:paddingTop="?attr/actionBarSize"
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)