我必须在向上滚动时隐藏底部导航视图并在向下滚动时显示。如何实现这个?我的布局是这样的
<?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>
我附上了视图的屏幕截图。请检查一下。
原文由 Karthik Thunga 发布,翻译遵循 CC BY-SA 4.0 许可协议
更新 只需将一个属性添加到
BottomNavigationView
材质库 AndroidX
支持库版本
28.0.0
或higher version
**旧答案(仍然有效)**
您需要一个辅助类来执行此操作。此解决方案类似于 Google Material Design Guideline。
创建一个类
BottomNavigationViewBehavior
要使用此行为,您需要使用协调器布局…
将此代码添加到包含底部导航的 Activity 中。