【问题标题】:How to hide BottomNavigationView when recylerview scrolls uprecyclerview向上滚动时如何隐藏BottomNavigationView
【发布时间】:2021-10-10 14:42:31
【问题描述】:

您好,我想在 recylerview 向上滚动时隐藏底部导航,但在 recylerview 向下滚动并且当 recylerview 停止时我希望底部导航出现 也喜欢幻灯片动画,就像底部工作表一样

我有一个主要活动,其中我给出了底部导航和一个片段容器作为包含片段容器包含我的所有片段

这是我的代码

请注意,如果有人想要更多代码参考,请告诉我我会 更新问题

好的,我在 bootom nav xml 中使用了app:layout_behavior="@string/hide_bottom_view_on_scroll_behavior",但它不起作用

activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/black"
    tools:context=".MainActivity">


    <include
        android:id="@+id/fragment_container"
        layout="@layout/fragment_container"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

    <include
        android:id="@+id/bottom_navigation_view"
        layout="@layout/bottom_navigation_view" />


</RelativeLayout>

bottom_nav_view.xml

<?xml version="1.0" encoding="utf-8"?>
<com.google.android.material.bottomnavigation.BottomNavigationView xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/bottom_navigation_view_layout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_marginStart="30dp"
    android:layout_marginEnd="30dp"
    android:layout_marginBottom="10dp"
    android:background="@drawable/bottom_navigation_style"
    android:elevation="5dp"
    app:itemIconSize="30dp"
    app:itemIconTint="@color/white"
    app:itemRippleColor="@android:color/transparent"
    app:labelVisibilityMode="unlabeled"
    app:layout_behavior="@string/hide_bottom_view_on_scroll_behavior"
    app:menu="@menu/bottom_navigation">


</com.google.android.material.bottomnavigation.BottomNavigationView>

【问题讨论】:

    标签: android android-recyclerview bottomnavigationview


    【解决方案1】:

    你需要使用CoordinatorLayout来实现这个“滚动隐藏”功能:

    <androidx.coordinatorlayout.widget.CoordinatorLayout    //root Layout   
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
    
        <androidx.core.widget.NestedScrollView    //or RecyclerView
            android:layout_width="match_parent"
            android:layout_height="match_parent">
    
            <LinearLayout
                android:id="@+id/main_linearLayout"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:orientation="vertical" />
    
        </androidx.core.widget.NestedScrollView>
    
        <com.google.android.material.bottomnavigation.BottomNavigationView
            android:id="@+id/main_bottomNavigationView"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="bottom"
            android:background="@android:color/white" 
    

    app:layout_behavior="com.google.android.material.behavior.HideBottomViewOnScrollBehavior" app:menu="@menu/main" />

    </androidx.coordinatorlayout.widget.CoordinatorLayout>
    

    演示:https://youtu.be/3Gpeg6M82n4

    【讨论】:

    • brother recyclerviews 在不同的片段中,这些片段与片段容器一起使用,底部导航处于主要活动中,而不是单独在每个片段上
    猜你喜欢
    • 2017-08-25
    • 1970-01-01
    • 1970-01-01
    • 2015-05-01
    • 2015-11-17
    • 2016-01-17
    • 1970-01-01
    • 1970-01-01
    • 2021-08-29
    相关资源
    最近更新 更多