滚动时隐藏/显示底部导航视图

61

我需要在向上滚动时隐藏底部导航栏,在向下滚动时显示出来。如何实现这一功能? 我的布局如下:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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">


    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        android:layout_above="@+id/navigation"
        android:layout_alignParentTop="true"
        android:layout_marginBottom="5dp">

        <FrameLayout
            android:id="@+id/container1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
          />


    </LinearLayout>

    <android.support.design.widget.BottomNavigationView
        android:id="@+id/navigation"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:background="?android:attr/windowBackground"
        app:layout_scrollFlags="scroll|enterAlways|snap"
        app:menu="@menu/dashboard_slider_menu" />

</RelativeLayout>

这是我的视图截屏,请查看。

在此输入图片描述


你尝试过什么? - MRX
1
在您的列表视图/回收视图上添加事件/手势监听器。根据事件隐藏/显示。 - SripadRaj
你正在使用RecyclerView吗? - Anil
呀,我正在使用RecyclerView。 - Karthik Thunga
@KarthikThunga,请查看我下面的答案。 - Abhishek Singh
11个回答

0
 mScrollView.setOnScrollChangeListener(new NestedScrollView.OnScrollChangeListener() {
            @Override
            public void onScrollChange(NestedScrollView v, int scrollX, int scrollY, int oldScrollX, int oldScrollY) {


                if((scrollY > oldScrollY)) {

                        navigationView.setVisibility(View.GONE);

                }else {

                        navigationView.setVisibility(View.VISIBLE);

                }
            }

        });

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接