3

I have a viewpager in the containerActivity hosting two fragments, both having recyclerview, The floating action button is in the container activity, I want to hide fab on recyclerview scrolling.

This StackOverFlow post has the solution

But the problem is how to notify the fab in container activity that the recyclerview in the fragment is scrolled.

I am new to android, So any help would be appreciated. Thanks!

Community
  • 1
  • 1
Haaris Ahamed
  • 317
  • 3
  • 15

1 Answers1

3

try this method. it worked for me

mRecyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
    super.onScrolled(recyclerView, dx, dy);
    if (dy > 0 && mFloatingActionButton.getVisibility() == View.VISIBLE) {
        mFloatingActionButton.hide();
    } else if (dy < 0 && mFloatingActionButton.getVisibility() != View.VISIBLE) {
        mFloatingActionButton.show();
    }
}});
Shubham Sharma
  • 166
  • 1
  • 7