Using Google Design Library how to hide FAB button on Scroll down?

drlobo picture drlobo · Aug 16, 2015 · Viewed 36k times · Source

Google have released Design library, I am using

 compile 'com.android.support:design:22.2.1'

However I cant see any code examples of how to use this library and how to animate the FAB bar on scroll. I guess I can listen for scroll events on the ListView and then animate the button myself, but is this not baked into the API (is this not the point of this support library).

Is there examples for this ?

Answer

tochkov picture tochkov · Jan 14, 2016

If you're using RecyclerView and you're looking for something simple, you can try this:

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

By replacing 0 with a constant, you can adjust the sensitivity of triggering, providing smoother experience