【发布时间】:2015-09-29 20:52:40
【问题描述】:
我有一个 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 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 拦截的滚动更改?行为是正确的方式吗?
【问题讨论】:
标签: android android-recyclerview onscrolllistener android-coordinatorlayout