我有一个垂直的LinearLayout,里面有一个RecyclerView,可以上下滚动。最近,我在RecyclerView上附加了一个ItemTouchHelper回调,以便可以通过向左或向右拖动来排除其项,问题是侧面拖动很容易被接受,并且移动被误解了,干扰了上下滚动动作,我已经阅读了ItemTouchHelper.Callback文档,并且没有发现任何有用的东西,因为拖动选项的唯一属性是UP以及DOWN,END和START,RIGHT和LEFT。
我也在考虑从RecyclerView移除侧面滑动并将其整体附加到列表,因此在执行此操作时显示其他列表,解决方案是否相同,因为无论如何都会有这两种可能的运动? >这是我的ItemTouch.Callback代码:
private void recyclerSwipe(){
ItemTouchHelper.Callback itemTouch= new ItemTouchHelper.Callback() {
/**getMovementFlags()
* configuring the movements behavior
* */
@Override
public int getMovementFlags(@NonNull RecyclerView recyclerView, @NonNull RecyclerView.ViewHolder viewHolder) {
/**ACTION_STATE_IDLE
* denies drag and drop movements
* (up, down, left, right)
* */
int dragFlags=ItemTouchHelper.ACTION_STATE_IDLE;
/**START,END
* allows swiping a recyclerView side to side
* */
int swipeFlags=ItemTouchHelper.START|ItemTouchHelper.END;
return makeMovementFlags(dragFlags,swipeFlags);
}
@Override
public boolean onMove(@NonNull RecyclerView recyclerView, @NonNull RecyclerView.ViewHolder viewHolder, @NonNull RecyclerView.ViewHolder viewHolder1) {
return false;
}
/**onSwiped()
* setting reactions to user's drags
* */
@Override
public void onSwiped(@NonNull RecyclerView.ViewHolder viewHolder, int i) {
deleteTransaction(viewHolder);
}
};
/**attaching swipe to a recyclerView instance*/
new ItemTouchHelper(itemTouch).attachToRecyclerView(recView);
}