【问题标题】:Does not hide BottomAppBar when scrolling滚动时不隐藏 BottomAppBar
【发布时间】:2019-12-29 18:39:01
【问题描述】:

我不知道如何在滚动 ViewPager 内容时隐藏 BottomAppBar。 ViewPager 的片段之一如下所示:

<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 的布局看起来像:

<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时的隐藏,请告诉我你需要做什么才能得到结果?

【问题讨论】:

    标签: android material-design


    【解决方案1】:

    在带有 RecyclerView 的片段中,我找到了 BottomAppBar 并放置了滚动侦听器。根据滚动,我隐藏或显示 BottomAppBar。

    在 onCreateView 方法中:

       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();
                }
    
            }
    
        });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-06-17
      • 2019-07-28
      • 2020-11-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多