0

i want to hide my FloatingActionMenu when there's a scrolling inside my nested scroll view. i'm using a 3rd party library for an action menu , Clans-FloatingActionButton i found out a class for layout_behavior , but the most of the methods are Deprecated Here's the class :

public class FabMenuBehavior extends CoordinatorLayout.Behavior<FloatingActionMenu> {

private int accumulator = 0;
private int threshold = 0;

public FabMenuBehavior() {
    super();
}

public FabMenuBehavior(Context context, AttributeSet attrs) {
    super(context, attrs);
}

@Override
public boolean onStartNestedScroll(CoordinatorLayout coordinatorLayout, FloatingActionMenu child, View directTargetChild, View target, int nestedScrollAxes) {
    threshold = (child.getChildCount() > 0 ? child.getChildAt(0).getHeight() : child.getHeight()) / 2;
    return true;
}

@Override
public void onNestedScroll(CoordinatorLayout coordinatorLayout, FloatingActionMenu child, View target, int dxConsumed, int dyConsumed, int dxUnconsumed, int dyUnconsumed) {
    super.onNestedScroll(coordinatorLayout, child, target, dxConsumed, dyConsumed, dxUnconsumed, dyUnconsumed);
    if ((accumulator * dyConsumed) < 0) { //scroll direction change
        accumulator = 0;
    }
    accumulator += dyConsumed;

    if (accumulator > threshold && !child.isMenuButtonHidden()) {
        child.hideMenuButton(true);
    } else if (accumulator < -threshold && child.isMenuButtonHidden()) {
        child.showMenuButton(true);
    }
}

@Override
public void onStopNestedScroll(CoordinatorLayout coordinatorLayout, FloatingActionMenu child, View target) {
    super.onStopNestedScroll(coordinatorLayout, child, target);
    accumulator = 0;
}

}

So how can achieve that ? thank you.

Tamim Attafi
  • 2,253
  • 2
  • 17
  • 34
  • Does your code work? – dazza5000 Jan 14 '18 at 23:10
  • Unfortunately It's Deprecated – Tamim Attafi Jan 14 '18 at 23:10
  • You can still use deprecated methods until they are removed. Did you try this? https://stackoverflow.com/questions/33208613/hide-floatingactionbutton-on-scroll-of-recyclerview – dazza5000 Jan 14 '18 at 23:12
  • I know , this class works perfectly.. But i don't want to have any troubles later when the methods get removed – Tamim Attafi Jan 14 '18 at 23:19
  • If you clicked into the deprecated classes/methods do they tell you which classes/methods are recommended to use instead? – dazza5000 Jan 14 '18 at 23:30
  • thats what it says : Overrides deprecated method in 'android.support.design.widget.CoordinatorLayout.Behavior' less... This inspection reports where deprecated code is used in the specified inspection scope – Tamim Attafi Jan 15 '18 at 19:11

0 Answers0