问题描述
-------------
| 1 | 2 |
| | |
-------------
| 3 | 4 |
| | |
-------------
| 5 |
| |
-------------
| 6 |
| |
-------------
| 7 |
| |
-------------
如您所见,前4个项目的跨度大小为1,其余(5,6,7)的跨度大小为2。 我想通过保持跨度大小使其可拖动。目前,我的代码保留跨度,但是每1步更改都会更新适配器(这意味着,如果要将7拖动到4,则首先将7替换为6 -stops-,然后将7替换为5 -stops-,然后将7替换为7。 4.)因此,不允许我直接更改7-> 4。 (在用户方面很烦人。)
另外,如果我想更改7-> 4,则我希望第3项保持在中心,因为7的跨度不适合4的位置。就是这样:
-------------
| 1 | 2 |
| | |
-------------
| 3 |
| |
-------------
| 7 |
| |
-------------
| 5 |
| |
-------------
| 6 |
| |
-------------
| 4 |
| |
-------
这是我的itemtouchhelper:
class RecyclerViewitemtouchhelper<T>(private val mAdapter: SimpleRecyclerViewAdapter<T,*>,shouldSwapDiff: Boolean = true) : itemtouchhelper(object : itemtouchhelper.Callback() {
override fun isLongPressDragEnabled() = true
override fun isItemViewSwipeEnabled() = false
override fun getMovementFlags(recyclerView: RecyclerView,viewHolder: RecyclerView.ViewHolder): Int {
val dragFlags = UP or DOWN or LEFT or RIGHT
val swipeFlags = if (isItemViewSwipeEnabled) START or END else 0
return makeMovementFlags(dragFlags,swipeFlags)
}
override fun onMove(recyclerView: RecyclerView,viewHolder: RecyclerView.ViewHolder,target: RecyclerView.ViewHolder): Boolean {
val fromPosition = viewHolder.bindingAdapterPosition
val toPosition = target.bindingAdapterPosition
Collections.swap(mAdapter.data,fromPosition,toPosition)
mAdapter.notifyItemmoved(fromPosition,toPosition)
return true
}
override fun onSwiped(viewHolder: RecyclerView.ViewHolder,direction: Int) {
}
})
那么如何使拖动平滑并根据跨度动态设置项目的边距?
谢谢。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)