Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hide FAB onScrollView #24

Closed
douglasscriptore opened this issue May 8, 2015 · 5 comments
Closed

Hide FAB onScrollView #24

douglasscriptore opened this issue May 8, 2015 · 5 comments

Comments

@douglasscriptore
Copy link

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

Thank you

@vbaidak
Copy link
Member

vbaidak commented May 8, 2015

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
#24.

@douglasscriptore
Copy link
Author

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
Copy link
Member

vbaidak commented May 8, 2015

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
Copy link
Author

wow great, thanks.

@vbaidak
Copy link
Member

vbaidak commented May 12, 2015

Issue solved

@vbaidak vbaidak closed this as completed May 12, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants