I find FloatingActionsMenu library suitable for chaining floating actions buttons. Regardless it isn’t maintained regularly, it still does the work, if you don’t have time writing your own layout for the same purpose.

Beside it is being limited in features, it lacks Behavior that will make it behave in CoordinatorLayout.

So why not write ourselves one, huh?

What I needed from the Behavior

I intended to write a Behavior that will toggle the FloatingActionsMenu when the content is scrolled.

1. Hide the normal sized FAB when the content is scrolled up.

2. Show the normal sized FAB when the content is scrolled down.

3. (Optional) Collapse the menu, if you have more than one FAB.

Behavior

We are interested in acting upon vertical scroll only. When the nested scroll is started, we need to signal if we are interested in the nested scrolling, so our FloatingActionsMenu becomes target that will receive nested scroll events.

@Override

public boolean onStartNestedScroll(CoordinatorLayout coordinatorLayout, FloatingActionsMenu child, View directTargetChild, View target, int nestedScrollAxes) {

return nestedScrollAxes == ViewCompat.SCROLL_AXIS_VERTICAL;

}

Next, we need to react on nested scrolls, by differentiating between scrolling up and down. We accumulate total vertical scrolled distances, upon which we should course our actions. Also it is important to handle when there is change in scroll directions. When we are scrolling up our mTotalDy is always positive, since dyConsumed is positive. When scrolling down, these two are holding negative values, hence the ternary statement.

If you want to take actions upon slightest change in nested scroll events, you might consider dropping the conditions about total scrolled value and menu height and just check for direction changes.