Search code examples
androidandroid-studioanimationscrollbarfloating-action-button

Hiding FAB when the user scroll through screen


my problem is I want to hide the Love FAB when the user scroll down to reviews and shows again when the user goes up again how can i achieve this behaviour ?

enter image description here

and this is what looks like now

enter image description here

my XML file is this:

FAB.xml

I cannot post it here because it's so long.


Solution

  • Thanks to Barns I have come with the solution by set the visibility property to GONE or INVISIBLE

    and implementing the nestedScrollView.setOnScrollChangeListener

    this code sample works fine for me:

            nestedScrollView.setOnScrollChangeListener(new View.OnScrollChangeListener() {
            @Override
            public void onScrollChange(View v, int scrollX, int scrollY, int oldScrollX, int oldScrollY) {
    
                //the Y-axis scroll origin value
                if( scrollY > 275) {
                    Log.i("Scroll", "onScrollChange: 275 Reached");
                    loveFab.setVisibility(View.INVISIBLE);
                }
                else
                    loveFab.setVisibility(View.VISIBLE);
    
    
            }
        });