leochuan / ViewPagerLayoutManager

ViewPager like LayoutManager which supports some awesome animations and infinite scroll.
Apache License 2.0
1.75k stars 330 forks source link

刷新的索引会出现问题 #46

Closed CuiBow closed 6 years ago

CuiBow commented 6 years ago

当滑动结束拿到currentPosition 刷新适配器会出现索引错乱的问题

leochuan commented 6 years ago

描述的能具体一点吗?

CuiBow commented 6 years ago

适配器onBindViewHolder的索引不是当前rv显示的item的索引

leochuan commented 6 years ago

我的意思是 滑动结束拿到 currentPosition 刷新适配器 是什么操作,方便的话代码贴一下

CuiBow commented 6 years ago

if (newState == RecyclerView.SCROLL_STATE_IDLE) { if (currentPosition != layoutManager.getCurrentPosition()) { currentPosition = layoutManager.getCurrentPosition(); for (int i = 0; i < departmentListBean.size(); i++) { departmentListBean.get(i).setSelect(false); } departmentListBean.get(currentPosition).setSelect(true); adapter.notifyDataSetChanged(); if (doctorsList != null) { initViewPager(doctorsList.get(currentPosition)); } } }

leochuan commented 6 years ago

所以你要做的事情是在滑动结束的时候,将当前的item的状态变成已选择是吗?

CuiBow commented 6 years ago

是的 当选中之后改变当前item的显示状态

leochuan commented 6 years ago

我试了下 并没有什么问题 你有开无限滚动 或者有用 CenterSnapHelper

CuiBow commented 6 years ago

这是我的设置代码 centerSnapHelper = new CenterSnapHelper(); layoutManager = new CircleLayoutManager(getActivity()); layoutManager.setGravity(CircleLayoutManager.TOP); float startNum = 750; float endNum = 1080; float proportion = startNum / endNum; layoutManager.setRadius((int) (ScreenUtils.getScreenWidth() proportion)); layoutManager.setInfinite(true); float speed = 15 0.005f; layoutManager.setMoveSpeed(speed);

leochuan commented 6 years ago

这样设置并没有什么问题,你adapteronBindViewHolder贴上来 看一下

leochuan commented 6 years ago

378534547, 这是我qq

CuiBow commented 6 years ago

https://github.com/CuiBow/TestViewPager 这是我修改的demo您可以看一下 快速滑动就会出现问题

akebrt commented 6 years ago

层主怎样解决的?我这边也遇到了

CuiBow commented 6 years ago

viewPagerLayoutManager.setMaxVisibleItemCount();

18813018517 邮箱:18813018517@163.com

签名由 网易邮箱大师 定制

在2018年02月28日 18:13,akebrt 写道:

层主怎样解决的?我这边也遇到了

— You are receiving this because you modified the open/close state. Reply to this email directly, view it on GitHub, or mute the thread.

leochuan commented 6 years ago

他是因为实际的数据量,少于屏幕显示的数据数量 比如list里的数据只有2个 但是屏幕上能显示3个 所以其实屏幕上的两个view绘制的都是同一个数据表示同一个position 我给他的建议是在数据量很小时setMaxVisibleItemCount()控制一下屏幕上能显示View的数量

akebrt commented 6 years ago

可以解决。谢谢

MaosanDao commented 5 years ago

已解决,谢谢