【发布时间】:2019-12-28 21:27:02
【问题描述】:
我刚刚实现了一个底部导航(AS的默认-文件->新建->活动->底部导航活动)一切都很好,除了nav_host_fragment顶部的空间。
由于它是在 ConstraintLayout 中生成的,因此我尝试清理约束并将顶部约束设置为 parent,将 margin 设置为 '0dp' 并将 height 设置为 match_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>
【问题讨论】:
-
这看起来像
<RelativeLayout>上的android:paddingTop="?attr/actionBarSize"。 -
您使用的是什么主题?也许是为“ActionBar”保留空间?
-
@MikeM。这正是造成空间的原因。我不敢相信我没有注意到这一点!谢谢!
-
您可以将此评论作为答案发布,以便我标记为适合此问题的评论。
-
没问题。我很好。 :-) 没什么大不了的。只是一个小小的疏忽。如果您愿意,请随时自行发布答案,或删除此问题。不过谢谢。我很感激这个提议。干杯!
标签: android android-fragments bottomnavigationview