Skip to content

Conversation

@lindroy
Copy link

@lindroy lindroy commented Jun 12, 2022

在相册中添加一张本地图片,然后拖拽本地图片将其移动到中间位置,比如从下标6移动到下标4,接着再移除第5和第6张图片,其中有一种会无法移除,这是因为使用Collections.swap替换位置后会导致图片下标错乱,从如下的日志可以清楚看到:

--------------拖拽前--------------
0:https://p.qqan.com/up/2022-2/16454222068823469.jpg
1:https://p.qqan.com/up/2022-2/16454222074615293.jpg
2:https://p.qqan.com/up/2022-2/16454222079248915.jpg
3:https://p.qqan.com/up/2022-2/16454222074882536.jpg
4:https://p.qqan.com/up/2022-2/16454222077125944.jpg
5:https://p.qqan.com/up/2022-2/16454222079542524.jpg
6:/storage/emulated/0/Pictures/知乎/1652198422920.jpeg
--------------拖拽后--------------
0:https://p.qqan.com/up/2022-2/16454222068823469.jpg
1:https://p.qqan.com/up/2022-2/16454222074615293.jpg
2:https://p.qqan.com/up/2022-2/16454222079248915.jpg
3:https://p.qqan.com/up/2022-2/16454222074882536.jpg
4:/storage/emulated/0/Pictures/知乎/1652198422920.jpeg
5:https://p.qqan.com/up/2022-2/16454222079542524.jpg
6:https://p.qqan.com/up/2022-2/16454222077125944.jpg

正确的结果应该是下标 6 移动到下标 4 后,原来的 4 和 5 依次变成 5 和 6,但只替换的话原来的 5 没有变化。由于删除时是按照下标删除的,会导致删除出错。所以拖拽后应该先将移动的图片从集合中移除,再插入相应的位置。

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.

1 participant