我有一个RecyclerView,我添加了可以在列表项上执行的不同操作。特别是,DragDrop
和SwipeDismiss
。 DragDrop
由长按启动,SwipeDismiss
由刷卡启动。我必须留意滚动事件以阻止这些行为的发生。滚动令人讨厌,然后突然转为拖动。在我添加一个OnScrollListener
来处理这个问题之前。CoordinatorLayout与RecyclerView:onScroll
这是我之前做过:
@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 for collapsable toolbars。现在滚动时,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
拦截我的回收站鉴于这些滚动的变化?行为是否正确?
这是一个很好的博客,但它不提供解决我的问题。协调员布局是根视图,正在拦截我的触摸。那就是滑动和拖拽,而且我的工作很好。我需要解决滚动没有传递给recyclerView。 –
嗯,不,你没有一切正常:否则你根本就没有问题。你会有很多很容易的时间用'ItemTouchHandler'清除你的滑动/拖动代码,它很好地适用于'CoordinatorLayout'和嵌套滚动。 – ianhanniballake
是的,这里有一个问题,因为我没有问题,我的刷卡和拖动。就像我的问题所说的那样,在我添加折叠工具栏之前,这一切都正常。协调员布局在滚动到达回收站视图之前拦截滚动。我不认为可以对回收站视图进行任何更改,因为根视图首先得到所有接触。它必须在协调员布局中。 –