滚动时不隐藏BottomAppBar [英] Does not hide BottomAppBar when scrolling
本文介绍了滚动时不隐藏BottomAppBar的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我不知道如何在滚动 ViewPager 内容时隐藏 BottomAppBar.ViewPager的片段之一如下所示:
I can't figure out how to hide the BottomAppBar while scrolling the ViewPager content. One of the fragments for ViewPager looks like this:
<androidx.coordinatorlayout.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/days_fragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/RVDays"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</androidx.coordinatorlayout.widget.CoordinatorLayout>
,因此ViewPager的布局如下:
and so the layout with ViewPager looks like:
<androidx.constraintlayout.widget.ConstraintLayout
.................>
<com.google.android.material.tabs.TabLayout
................./>
<androidx.viewpager.widget.ViewPager
android:id="@+id/viewpager"
android:layout_width="match_parent"
android:layout_height="0dp"
android:background="@android:color/white"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/sliding_tabs" />
<androidx.coordinatorlayout.widget.CoordinatorLayout
android:id="@+id/coordinatorLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_constraintBottom_toBottomOf="parent">
<com.google.android.material.bottomappbar.BottomAppBar
android:id="@+id/bottom_app_bar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
app:backgroundTint="@color/colorPrimary"
app:fabAlignmentMode="center"
app:menu="@menu/days_bottomappbar_menu"
app:hideOnScroll="true"
app:layout_scrollFlags="scroll|enterAlways"/>
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_add_24px"
app:layout_anchor="@id/bottom_app_bar" />
</androidx.coordinatorlayout.widget.CoordinatorLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
我想在滚动RecyclerView时实现隐藏,请告诉我您需要做些什么才能得到结果?
I would like to achieve hiding when scrolling RecyclerView, please tell me what you need to do to get the result?
推荐答案
在带有RecyclerView的片段中,我找到了BottomAppBar并将滚动侦听器放入.根据滚动,我隐藏或显示BottomAppBar.
In the fragment with RecyclerView I find BottomAppBar and put the scroll listener. Depending on the scrolling, I hide or show the BottomAppBar.
在onCreateView方法中:
In the onCreateView method:
mBottomAppBar = getActivity().findViewById(R.id.bottom_app_bar);
mDayRecyclerView.addOnScrollListener(new RecyclerView.OnScrollListener(){
@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy)
{
if (dy>0)
{
mBottomAppBar.performHide();
}
if (dy<0)
{
mBottomAppBar.performShow();
}
}
});
这篇关于滚动时不隐藏BottomAppBar的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文