原代码片段如下:
<androidx.constraintlayout.widget.ConstraintLayout 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"
tools:context=".Activity.MainActivity">
<androidx.viewpager.widget.ViewPager
android:id="@+id/view_pager"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="@+id/nav_view"
参考了部分文档如:https://blog.csdn.net/weixin_41236261/article/details/79810007
均解决不了,查阅了部分资料理解后才解决了,:
1. 将高度改由自动实现(只此试验也不行),android:layout_height="0dp"
2. 将ViewPager底部与BottomNavigationView顶部约束(只此试验也不行),app:layout_constraintBottom_toTopOf="@+id/nav_view"
3. 顶部也得约束,否则各fragment顶部将被遮挡!!!!app:layout_constraintTop_toTopOf="parent"
上述红色部分更改为:
android:layout_height="0dp"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toTopOf="@+id/nav_view" />
本文详细介绍了如何解决在Android应用中ViewPager与BottomNavigationView布局冲突的问题,通过调整布局高度和约束条件,确保了各Fragment的正确显示,避免了顶部被遮挡的情况。

4053

被折叠的 条评论
为什么被折叠?



