I've implemented FloatingActionButton.Behavior
so the FAB hides when scrolling down.
The problem is when the view scrolled all the way down, items are deleted and the scrollbar is no longer visible, and so is the FAB.
I know I can set an OnGlobalLayoutListener
and make it show the FAB when scrollbar is done, but as the Adapter is currently unaware of the FAB I would like to keep it this way.
Is there a solution to be implemented within the FloatingActionButton.Behavior
class ?
Here is the Behavior
implementation :
public class FABAwareScrollingViewBehavior extends FloatingActionButton.Behavior {
public FABAwareScrollingViewBehavior(Context context, AttributeSet attrs) {
super();
}
@Override
public void onNestedScroll(CoordinatorLayout coordinatorLayout, FloatingActionButton child, View target, int dxConsumed, int dyConsumed, int dxUnconsumed, int dyUnconsumed) {
super.onNestedScroll(coordinatorLayout, child, target, dxConsumed, dyConsumed, dxUnconsumed, dyUnconsumed);
if (dyConsumed > 0 && child.getVisibility() == View.VISIBLE) {
child.hide();
} else if (dyConsumed < 0 && child.getVisibility() == View.GONE) {
child.show();
}
}
@Override
public boolean onStartNestedScroll(CoordinatorLayout coordinatorLayout, FloatingActionButton child, View directTargetChild, View target, int nestedScrollAxes) {
return nestedScrollAxes == ViewCompat.SCROLL_AXIS_VERTICAL;
}
}