当viewpager片段滚动时隐藏底部导航视图

时间:2020-07-27 12:16:39

标签: android xml kotlin layout android-bottomnavigationview

我在 ViewPager 中使用了 BottomNavigationView 。我的 main.xml 如下所示-

<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout
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:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".Fragment_Handler">

    <com.google.android.material.appbar.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:theme="@style/AppTheme.AppBarOverlay">

        <androidx.appcompat.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="?attr/colorPrimary"
            app:layout_scrollFlags="scroll|enterAlways"
            app:popupTheme="@style/AppTheme.PopupOverlay">

        </androidx.appcompat.widget.Toolbar>
    </com.google.android.material.appbar.AppBarLayout>

   <androidx.viewpager.widget.ViewPager
        android:id="@+id/viewPager"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:layout_behavior="com.google.android.material.appbar.AppBarLayout$ScrollingViewBehavior"
        android:background="#efefef" /> 


    <com.google.android.material.bottomnavigation.BottomNavigationView
        android:id="@+id/tabLayout"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom"
        android:background="@android:color/background_light"
        app:itemIconTint="@color/tab_selector"
        app:labelVisibilityMode="labeled"
        app:layout_behavior="com.google.android.material.behavior.HideBottomViewOnScrollBehavior"
        app:menu="@menu/tab_nav_menu"

        />
</androidx.coordinatorlayout.widget.CoordinatorLayout>

下面是我的 fragment1.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="match_parent"
    android:layout_height="match_parent">
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout
    android:id="@+id/swipe_refresh_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <androidx.recyclerview.widget.RecyclerView
        android:id="@+id/rcview"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:scrollbars="none"
        android:saveEnabled="true"
        android:background="@color/color_blur"/>
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>

</RelativeLayout>

当我在Fragment1中滚动 RecyclerView 时, BottomNavigationView 不会隐藏。但是,当我使用 NestedScrollView 进行尝试时, BottomNavigationView 可以根据需要正常工作。当实现上述XML代码时,为什么 BottomNavigationView 没有隐藏?

0 个答案:

没有答案