youlookwhat / ByRecyclerView

🔥 RecyclerView 下拉刷新、上拉松手/自动加载更多、item点击/长按、item局部刷新、头布局/尾布局/状态布局、万能分割线、Skeleton骨架图、极简adapter、嵌套滑动置顶
https://youlookwhat.github.io/ByRecyclerView
Apache License 2.0
798 stars 139 forks source link

九宫格图片,当可以拖动排序时,Item的间距会越变越大 #21

Closed Khaos116 closed 3 years ago

Khaos116 commented 3 years ago

GIF

Khaos116 commented 3 years ago

数据切换后调用RecyclerView.adapter.notifyItemMoved刷新触发

youlookwhat commented 3 years ago

你的意思是,你使用了YImagePicker,和ByRecyclerView搭配使用,然后在 YImagePicker数据切换后调用RecyclerView.adapter.notifyItemMoved刷新会触发间隔变大的问题,是吗?

Khaos116 commented 3 years ago

https://github.com/LidongWen/MultiTypeAdapter/blob/master/app/src/main/java/com/wenld/app_multitypeadapter/itemTouch/ItemTouchMoveListener.java 我用的是这个,做的数据切换,没有使用YImagePicker和ByRecyclerView(我只用了你的万能分割线)

Khaos116 commented 3 years ago

image 不知道是不是这个刷新方法导致的

youlookwhat commented 3 years ago

你是用到了 ByRectclerView的哪个地方

Khaos116 commented 3 years ago

我只用了你的分割线 普通的RecyclerView+MultiType的adapter( https://github.com/drakeet/MultiType )+ ItemTouchMoveListener

Khaos116 commented 3 years ago

https://github.com/airbnb/epoxy/blob/master/epoxy-adapter/src/main/java/com/airbnb/epoxy/EpoxyItemSpacingDecorator.java 我用这个分割线,拖拽item间隔高度不会变化,但是它会导致count为3的时候第二个的高度比第一个和第三个要低一点,网上找了好多个分割线,很多都会出现高度不对或者是间隔变大的问题。你这个号称万能分割线,所以就给你提个bug,看能不能兼容,不能兼容就算了

youlookwhat commented 3 years ago

你试试在RecyclerView.adapter.notifyItemMoved后面加上这个:

            recyclerView.post(new Runnable() {
                @Override
                public void run() {
                    recyclerView.invalidateItemDecorations();
                }
            });

就是在刷新结束后执行这个操作,这个是一个很坑的问题,很不好解决,你可以试试上面那个方法,我之前也发现了,使用上面的代码处理的。

Khaos116 commented 3 years ago

好的,我试试

Khaos116 commented 3 years ago

加了那个刷新没有效果,改成adapter的全局刷新就不会添加高度了(但是拖拽的那个替换效果变得不舒服了,因为是整体刷新了,导致那个切换动画没了) image

Khaos116 commented 3 years ago

根据这个现象,基本判断就是notifyItemMoved这个切换导致的高度变大

youlookwhat commented 3 years ago

是的,这个很难处理,我看很多ItemDecoration都有这个问题,如果实在达不到你要的效果,你可以不使用ItemDecoration,直接在adapter里动态设置分隔间距

Khaos116 commented 3 years ago

https://github.com/airbnb/epoxy/blob/master/epoxy-adapter/src/main/java/com/airbnb/epoxy/EpoxyItemSpacingDecorator.java 这个不会导致分割线间距变大,就是大小有些计算不准,你可以参考下 image

youlookwhat commented 3 years ago

他也是没有算准确,我看看

Khaos116 commented 3 years ago

我知道问题了,最左边和最右边的它只设置了left或者right,所以宽度会大一点,中间的设置了left和right,所以宽度会少1个left/right的宽度

youlookwhat commented 3 years ago

你说的是我这个问题吗,这个每次拖动上下间距会增大的问题

Khaos116 commented 3 years ago

我知道问题了,最左边和最右边的它只设置了left或者right,所以宽度会大一点,中间的设置了left和right,所以宽度会少1个left/right的宽度

这个我说的是EpoxyItemSpacingDecorator 每次间隔变大好像是间距不同导致的,我让上下间距一致,拖动后间距就不会再增大了

Khaos116 commented 3 years ago

优化了一下,虽然还是有点问题,不过不严重 https://www.jianshu.com/p/09b23b689748

youlookwhat commented 3 years ago

可以可以,我看看666