public abstract static class DragItemTouchHelper extends ItemTouchHelper.Callback {
private static final String TAG = "DragItemTouchHelper";
private DragAnswerAdapter adapter;
public DragItemTouchHelper(DragAnswerAdapter adapter) {
this.adapter = adapter;
}
@Override
public boolean isLongPressDragEnabled() {
return false;
}
@Override
public boolean isItemViewSwipeEnabled() {
return false;
}
@Override
public float getMoveThreshold(@NonNull RecyclerView.ViewHolder viewHolder) {
return 0.8f;
}
@Override
public int getMovementFlags(@NonNull RecyclerView recyclerView, @NonNull RecyclerView.ViewHolder viewHolder) {
if (adapter.isPosted() || !adapter.isEnabled()) {
return 0;
}
return makeMovementFlags(ItemTouchHelper.UP | ItemTouchHelper.DOWN | ItemTouchHelper.LEFT | ItemTouchHelper.RIGHT, 0);
}
@Override
public boolean onMove(@NonNull RecyclerView recyclerView, @NonNull RecyclerView.ViewHolder from, @NonNull RecyclerView.ViewHolder to) {
int fromPosition = from.getAdapterPosition(); //拖动的position
int toPosition = to.getAdapterPosition(); //释放的position return false;
RecyclerView 与 ViewPager横向拖拽事件冲突解决(horizontal drag conflicts between ViewPager and RecyclerView)
最新推荐文章于 2024-06-17 09:11:58 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)