Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

实现Grid效果 #2

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open

Conversation

protectedMan
Copy link

我从文件夹中把8号数字拖出来,结果只能插入到最右边一列,无法插入左边两列,请问如何设置
见视频
https://user-images.githubusercontent.com/17565737/232937530-d664b500-c73f-4dee-8803-6e2f0f7cee5a.mp4

@protectedMan protectedMan marked this pull request as ready for review April 19, 2023 00:53
@HeroZ-Dodge
Copy link
Collaborator

    /**
     * 根据拖拽位置,显示、隐藏预览项
     * @param viewHolder 被拖拽的ViewHolder
     * @param left viewHolder相对当前window的left
     * @param top  viewHolder相对当前window的top
     * @param activity 是否被拖动,释放拖动时 activity == false
     */
    private fun notifyPreviewViewHolder(viewHolder: RecyclerView.ViewHolder?, left: Float, top: Float, activity: Boolean) {
        if (activity) {
            val targetLeft = recyclerView.left.toFloat()
            val targetRight = recyclerView.right.toFloat()
            val targetWith = recyclerView.width
            val xStart = targetLeft - targetWith / 4
            val xEnd = targetRight - targetWith / 4
            if (left in xStart..xEnd) {
                val y = top - location[1]
                val position = findBestPosition(y.toInt(), recyclerView)
                updatePreviewPosition(position, viewHolder)
            } else {
                updatePreviewPosition(-1, viewHolder)
            }
        } else {
            replacePreview(viewHolder)
        }
    }

demo中的代码有注释,你把updatePreviewPosition(position, viewHolder) 这个position计算对了就可以了

@protectedMan
Copy link
Author

protectedMan commented Apr 19, 2023

312312312.mp4

大佬我按照你提供的相关方法完善了相关逻辑, 还有但是gird最后一列好像有点问题,不知道怎么处理,相关代码已经PR 可以帮我定位下问题吗?

@HeroZ-Dodge
Copy link
Collaborator

已经很接近了,把position的细节处理好就可以

@HeroZ-Dodge
Copy link
Collaborator

看了下你的提交,提点建议,你把IDragData这个文件下放到了 core ,IDragData 这个文件定义属于业务层
如果你需要实现文件夹不允许拖动的效果,你可以直接重写 IDragItem.canDrag 的实现。
image
而不是依赖具体的实现FolderData

@protectedMan
Copy link
Author

看了下你的提交,提点建议,你把IDragData这个文件下放到了 core ,IDragData 这个文件定义属于业务层
如果你需要实现文件夹不允许拖动的效果,你可以直接重写 IDragItem.canDrag 的实现。
image
而不是依赖具体的实现FolderData

我直接重写 FolderData 的 isCanDrag=false
image

用demo测试了下,文件下还可以拖动

@HeroZ-Dodge
Copy link
Collaborator

你要重写 FolderViewHolder ,IDragItem 和 IDragData 这两个接口你要区分下

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants