我有一个 RecyclerView,我在其中添加了可以对列表项执行的不同操作。特别是,DragDrop
和SwipeDismiss
。DragDrop
长按SwipeDismiss
启动,刷卡启动。我必须注意滚动事件以阻止这些动作的发生。滚动很烦人,然后突然切换到拖动。在我添加一个OnScrollListener
来处理这个之前。
这是我之前做的:
@Override
public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
super.onScrollStateChanged(recyclerView, newState);
if(newState == RecyclerView.SCROLL_STATE_IDLE){
drag.setCurrentAction(IDLE);
} else {
drag.setCurrentAction(SCROLL);
}
}
不再工作
我最近为可折叠工具栏添加了 CoordinatorLayout。现在向上滚动时,在工具栏折叠之前drag
不会设置为。SCROLL
我试图创建自己的行为,但这会取代我当前使用的行为;@string/appbar_scrolling_view_behavior
. 这删除了我想要的工具栏行为,并且无法通知我的drag
状态。
我试过的:
@Override
public boolean onStartNestedScroll(CoordinatorLayout cl, CollapsingToolbarLayout child, View directTargetChild,
View target, int nestedScrollAxes) {
if (nestedScrollAxes == ViewCompat.SCROLL_AXIS_VERTICAL) {
if (drag.getCurrentAction().ordinal() < SCROLL.ordinal()) {
/* No actions have started and we are scrolling. set the new action */
drag.setCurrentAction(SCROLL);
}
return true;
}
return super.onStartNestedScroll(cl, child, directTargetChild, target, nestedScrollAxes);
}
@Override
public void onStopNestedScroll(CoordinatorLayout coordinatorLayout, CollapsingToolbarLayout child, View target) {
super.onStopNestedScroll(coordinatorLayout, child, target);
if (drag.getCurrentAction() == SCROLL) {
drag.setCurrentAction(INVALID);
}
}
所以我的问题
我如何在我的回收站视图上监听那些被拦截的滚动更改CoordinatorLayout
?行为是正确的方式吗?