Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xingrz/f5935c1e2179d9feaaa8 to your computer and use it in GitHub Desktop.
Save xingrz/f5935c1e2179d9feaaa8 to your computer and use it in GitHub Desktop.
Hide FloatingActionButton while scrolling down
public class FloatingActionButtonScrollingBehavior extends FloatingActionButton.Behavior {
public FloatingActionButtonScrollingBehavior(Context context, AttributeSet attrs) {
super();
}
@Override
public boolean onStartNestedScroll(CoordinatorLayout coordinatorLayout,
FloatingActionButton child,
View directTargetChild, View target, int nestedScrollAxes) {
return nestedScrollAxes == ViewCompat.SCROLL_AXIS_VERTICAL;
}
@Override
public void onNestedScroll(CoordinatorLayout coordinatorLayout, FloatingActionButton child,
View target, int dxConsumed, int dyConsumed,
int dxUnconsumed, int dyUnconsumed) {
if (dyConsumed > 0) {
child.hide();
} else if (dyConsumed < 0) {
child.show();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment