0

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;
    }
}
SagiLow
  • 5,721
  • 9
  • 60
  • 115
  • This answer may help you. [http://stackoverflow.com/a/31618155/5978440] – Sniffer Apr 01 '17 at 11:35
  • @AkshayDighade Please be precise, how does it help? ***|||*** SagiLow, you're going to have to share your custom behavior implementation since it's the only place something could go wrong. – Eugen Pechanec Apr 01 '17 at 11:56
  • @EugenPechanec, implementation added. – SagiLow Apr 01 '17 at 12:00
  • @AkshayDighade the same happens when using the method described in the question you mentioned, in addition, this method only works on API+21 – SagiLow Apr 01 '17 at 12:03

0 Answers0