Scalified / fab

Floating Action Button Library for Android
Apache License 2.0
849 stars 164 forks source link

Hide FAB onScrollView #24

Closed douglasscriptore closed 9 years ago

douglasscriptore commented 9 years ago

Hello ! How do I hide FAB to scroll the page ?

Thank you

vbaidak commented 9 years ago

Hi,

Call hide() method in your scroll listener.

To show it again, call show() method.

Best wishes, Shell Software Inc. On 8 May 2015 19:00, "Douglas Scriptore" notifications@github.com wrote:

Hello ! How do I hide FAB to scroll the page ?

Thank you

— Reply to this email directly or view it on GitHub https://github.com/shell-software/fab/issues/24.

douglasscriptore commented 9 years ago

I'm using RecyclerView used the setOnScrollLister if anyone has doubts below is the code I used .

 @Override
        public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
            super.onScrolled(recyclerView, dx, dy);
            float y = recyclerView.getY();
            if(dy == 0){
                fab.show();
            }else if (y > dy) {
                fab.show();
            }else{
                fab.hide();
            }
        }
    });
vbaidak commented 9 years ago

I'm not sure whether this should work correctly.

getY() is actually an inherited method from android.view.View class, which returns the visual position of the RecyclerView.

In order to get this work, I suggest:

  1. Define some limit scroll value (you may use constant for this)
  2. Calculate the absolute Y-axis scroll change value
  3. If this absolute Y-axis scroll change value >= limit scroll value --> show or hide the ActionButton

The sample code may look like this:

    @Override
    public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
        int scrollLimit = 4 // convert this value to density-dependent pixel
        boolean scrollLimitReached = Math.abs(dy) >= scrollLimit;
        if (scrollLimitReached) {
            boolean scrollUp = dy >= 0;
            if (scrollUp) {
                actionButton.show();
            } else {
                actionButton.hide();
            }
        }
    }

Hope this helps. Good luck

douglasscriptore commented 9 years ago

wow great, thanks.

vbaidak commented 9 years ago

Issue solved