BottomNavigationView在滚动上隐藏/显示

时间:2018-10-02 11:49:19

标签: java android bottomnavigationview

好的,我知道这是重复的,但是我发现没有解决方案没有用。我不知道问题是什么,为什么它不起作用。我希望BottomNavigationView在向下滚动gridv时隐藏,而在向上滚动时显示。有人可以帮忙吗?

<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:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".layout.HomeActivity">

    <androidx.swiperefreshlayout.widget.SwipeRefreshLayout
        android:id="@+id/container"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <GridView
            android:id="@+id/gridLayout"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:numColumns="2"
            android:scrollbars="none" />

    </androidx.swiperefreshlayout.widget.SwipeRefreshLayout>

    <com.google.android.material.bottomnavigation.BottomNavigationView
        android:layout_alignParentBottom="true"
        app:layout_behavior="@string/hide_bottom_view_on_scroll_behavior"
        android:id="@+id/bottom_menu"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:itemIconTint="@drawable/clicl_menu"
        app:itemTextColor="@drawable/clicl_menu"
        app:menu="@menu/bottom_menu"/>

</RelativeLayout>

1 个答案:

答案 0 :(得分:0)

我会用CoordinatorLayoutapp:layout_scrollFlags来做到这一点:

<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=".layout.HomeActivity">

    <androidx.swiperefreshlayout.widget.SwipeRefreshLayout
        android:id="@+id/container"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <GridView
            android:id="@+id/gridLayout"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:numColumns="2"
            android:scrollbars="none" />

    </androidx.swiperefreshlayout.widget.SwipeRefreshLayout>

    <com.google.android.material.bottomnavigation.BottomNavigationView
        android:layout_alignParentBottom="true"
        android:id="@+id/bottom_menu"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:layout_scrollFlags="scroll|enterAlways"
        app:itemIconTint="@drawable/clicl_menu"
        app:itemTextColor="@drawable/clicl_menu"
        app:menu="@menu/bottom_menu"/>

</androidx.coordinatorlayout.widget.CoordinatorLayout>