NestedScrollView
当我在其中滚动时,我试图显示/隐藏 FAB CoordinatorLayout
。我实现了Behavior
您可以在此链接上查看的内容(github示例)。问题是在方法内部调用显示/隐藏OnNestedScroll
方法。不幸的是,有时当我滚动时,不会调用此方法。但是,onNestedScrollAccepted
方法总是被调用。我找不到任何不调用它的原因(比如 20-30% 的时间)。你知道为什么会这样吗?
这是我的行为课:
public class ScrollAwareFABBehavior extends CoordinatorLayout.Behavior {
FloatingActionMenu fabMenu;
Context cont;
public ScrollAwareFABBehavior(Context context, AttributeSet attrs) {
super();
cont =context;
}
@Override
public boolean onStartNestedScroll(CoordinatorLayout coordinatorLayout, View child,
View directTargetChild, View target, int nestedScrollAxes) {
if (nestedScrollAxes == ViewCompat.SCROLL_AXIS_VERTICAL)
{
return true;
}
return super.onStartNestedScroll(coordinatorLayout, child, directTargetChild, target,
nestedScrollAxes);
}
@Override
public void onNestedScroll(CoordinatorLayout coordinatorLayout, View child, View target,
int dxConsumed, int dyConsumed, int dxUnconsumed, int dyUnconsumed) {
fabMenu = (FloatingActionMenu) child;
Log.d("TAG","onNestedScroll"); // Sometimes it is not called
super.onNestedScroll(coordinatorLayout, child, target, dxConsumed, dyConsumed, dxUnconsumed,
dyUnconsumed);
if (dyConsumed > 0 && !fabMenu.isMenuButtonHidden()) {
fabMenu.hideMenuButton(true);
} else if (dyConsumed < 0 && fabMenu.isMenuButtonHidden()) {
fabMenu.showMenuButton(true);
}
}
@Override
public void onNestedScrollAccepted(CoordinatorLayout coordinatorLayout, View child, View directTargetChild, View target, int nestedScrollAxes) {
Log.d("TAG","Accepted"); //This is always called
onStartNestedScroll( coordinatorLayout, child, directTargetChild, target, nestedScrollAxes);
}
@Override
public void onStopNestedScroll(CoordinatorLayout coordinatorLayout, View child, View target) {
Log.d("TAG","STOP");
super.onStopNestedScroll(coordinatorLayout, child, target);
}
}