[英]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.