how to show/hide FAB on scroll Recycler view with coordinator parent

Zahra.HY picture Zahra.HY · Jan 17, 2017 · Viewed 12k times · Source

I have an activity with coordinator layout.inside activity there is a fragment with Recycler view and float button.how can I show/hide float button when Scroll Recycler view and avoid to use fab behavior?!

in activity layout: CoordinatorLayout----->AppBarLayout---->Toolbar and FrameLayout and Bottom bar view

in fragment layout: RelativeLayout---->Recycler view and float button

I want to implement something like Google+ home page. how can I implement this scenario?


Temporary I used this solution for my problem:

using coordinator layout of activity by interface in my fragment and show/hide fab with fab behavior ... until I find better solution!!!

Answer

Leandro Borges Ferreira picture Leandro Borges Ferreira · Jan 17, 2017

This code works just fine:

 mRecycler.addOnScrollListener(new RecyclerView.OnScrollListener() {
                @Override
                public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
                    if(dy > 0){
                        mFab.hide();
                    } else{
                        mFab.show();
                    }

                    super.onScrolled(recyclerView, dx, dy);
                }
            });

You cannot do:

app:layout_anchor="@id/listView"
app:layout_anchorGravity="bottom|end"

Look here:

There is no support built-in for CoordinatorLayout to work with ListView according to this Google post.