简体   繁体   English

RecyclerView拖放 - 使用ItemTouchHelper - 如何在拖动时更快地设置滚动速度?

[英]RecyclerView drag-drop - using ItemTouchHelper - How to set scrolling speed faster while dragging?

I tried this code for drag and drop : https://github.com/iPaulPro/Android-ItemTouchHelper-Demo . 我尝试使用此代码进行拖放操作: https//github.com/iPaulPro/Android-ItemTouchHelper-Demo

Here is a video : https://youtu.be/lMsv2jYpbi4 这是一段视频: https//youtu.be/lMsv2jYpbi4

Is there a way to speed up the scrolling during drag-and-drop ? 有没有办法加快拖放过程中的滚动?

In your class that extends ItemTouchHelper.Callback , override the method: 在扩展ItemTouchHelper.Callback的类中,重写方法:

@Override
public int interpolateOutOfBoundsScroll(RecyclerView recyclerView, int viewSize, int viewSizeOutOfBounds, int totalSize, long msSinceStartScroll) {
    final int direction = (int) Math.signum(viewSizeOutOfBounds);
    return 10 * direction;
}

This is a simple example which uses a fixed scroll speed, but if you wanted something that started slow and sped up (like the super.interpolateOutOfBoundsScroll does) you can do some maths based on the time since scrolling ( msSinceStartScroll ) and also the position in the overall scroll (example scroll faster when in the middle of the scroller and slower when you near the start/end). 这是一个使用固定滚动速度的简单示例,但如果您想要一些开始缓慢且加速的东西(如super.interpolateOutOfBoundsScroll那样),您可以根据滚动后的时间( msSinceStartScroll )以及位置中的位置进行一些数学计算。整体滚动(示例在滚动条中间滚动得更快,而在靠近开始/结束时滚动速度更慢)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 拖动时如何在使用 ItemTouchHelper 时取消 RecyclerView 中项目的拖动? - How to cancel dragging of items in RecyclerView when using ItemTouchHelper, as you drag? RecyclerView通过itemTouchHelper拖放,拖动时快速拖动 - RecyclerView drag & drop via itemTouchHelper bahaving strange when dragging fast "在 NestedScrollView 中带有 RecyclerView 的 ItemTouchHelper:拖动滚动不起作用" - ItemTouchHelper with RecyclerView in NestedScrollView: Drag scrolling not work Android - 使用 ItemTouchHelper.Callback 拖动 RecyclerView - Android - RecyclerView drag using ItemTouchHelper.Callback 如何使 RecyclerView 的 ItemTouchHelper 仅在列表的一部分上工作(拖放) - How to make the RecyclerView's ItemTouchHelper work on only part of the list(drag & drop) 如何使用ItemTouchHelper.Callback将项目拖放到水平recyclerview的边界上? - How to drag and drop items over bounds of the horizontal recyclerview with ItemTouchHelper.Callback? 使用 itemtouchhelper、recyclerview 和 Firestore 拖放项目,例如 Google Tasks - Drag & drop items with itemtouchhelper, recyclerview and Firestore like Google Tasks 如何使用ItemTouchHelper和游标实现拖放 - How to implement drag and drop with ItemTouchHelper and cursors RecyclerView ItemTouchHelper 动作拖动结束 - RecyclerView ItemTouchHelper Action Drag Ended RecyclerView ItemTouchHelper 动作拖动开始 - RecyclerView ItemTouchHelper Action Drag Started
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM