首页 文章

Android - 使用ItemTouchHelper.Callback进行RecyclerView拖动

提问于
浏览
1

我面临一个可能有人可以解决的问题 . 我需要 create a calendar and allow the user to select a date range by 1) clicking on a start date (this will create a 2 days range by default) and then 2) touching one range border and dragging it to increase or decrease that range .

目前我使用 RecyclerView with a GridLayoutManager 创建了所有日历天数单元格,其中包含很多行(所有周),每行7个项目(天) . 然后 I've used the RecyclerView ItemTouchHelperhttps://developer.android.com/reference/android/support/v7/widget/helper/ItemTouchHelper.htmland ItemTouchHelper.Callbackhttps://developer.android.com/reference/android/support/v7/widget/helper/ItemTouchHelper.Callback.htmlto complete the drag&drop functionality . 我的方法是使用那些助手提供的拖放检测(看看https://medium.com/@ipaulpro/drag-and-swipe-with-recyclerview-b9456d2b1aaf#.ib8r012gc)修改它以避免移动一个项目并且只检测我想要的触摸拖放手势 . 我已经通过删除默认拖动动画(覆盖ItemTouchHelper onDraw / onDrawOver)并使用ItemTouchHelper.Callback回调来管理拖动动作(没有交换适配器项目,因为我总是需要它们在同一位置)来正确完成功能 . 一切正常,但 I'm now facing a problem because the drag detection is not working as expected . 我将尝试解释它: if I start the drag movement in the center of a given cell, and I move to the cell to its left, the drag movement isn't triggered until I've reached the center (在我到达另一个单元格的最左侧之前触发的位置相同的位置 .

现在 I'm trying to play a bit with the ItemTouchHelper.Callback.chooseDropTarget method 在手指进入新单元格时手动选择放置目标,但我无法使其工作 . 我认为(但我无法确定)接收到的x,y坐标有些奇怪 .

我知道一些代码示例将非常有用,但我无法粘贴它,因为它属于一个私有和受保护的存储库:(

Any help that anyone could provide to me will be really appreciated . 当然,我会尝试等待这个主题提供我能提供的所有信息 . 我还会考虑 new different approaches and suggestions to get the "touch+move+up" movement ,我需要移动范围边界:)

非常感谢所有Stack Overflow社区!

1 回答

相关问题