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

底部indicator不准确的问题 #2

Open
EdwinSmartBoy opened this issue Feb 27, 2018 · 3 comments
Open

底部indicator不准确的问题 #2

EdwinSmartBoy opened this issue Feb 27, 2018 · 3 comments

Comments

@EdwinSmartBoy
Copy link

在使用过程中发现,底部的indicator在滑动到最后一页时,底部的indicator的标记展示在倒数第二个上,经过查找代码,发现是在BasePageIndicator的recyclerView的OnScrollListener的事件处理的问题,代码如下:
if (newState == RecyclerView.SCROLL_STATE_IDLE) {
LayoutManager layoutManager = recyclerView.getLayoutManager();
int position = 0;
if (layoutManager instanceof GridLayoutManager) {
GridLayoutManager gridLayoutManager = (GridLayoutManager) layoutManager;
position = gridLayoutManager.findFirstVisibleItemPosition(); //这句代码的问题
int row = gridLayoutManager.getSpanCount();
position = position / (row * mPageColumn);
} else if (layoutManager instanceof LinearLayoutManager) {
LinearLayoutManager linearLayoutManager = (LinearLayoutManager) layoutManager;
position = linearLayoutManager.findFirstVisibleItemPosition();
}
onPageSelected(position);
}
经过测试,发现在gridLayoutManager.findFirstVisibleItemPosition()在获取最后一页的第一个显示的item时的位置是错误的,比正确的position少了2,将该行代码修改如下,以上问题得到解决:
position = gridLayoutManager.findFirstCompletelyVisibleItemPosition();
修改后,得到的position的位置正确,以上问题得到解决。

@hanhailong
Copy link
Owner

@EdwinSmartBoy 赞,确实没注意

@EdwinSmartBoy
Copy link
Author

能实现点击按钮进行页面的切换吗?

@woniu0936
Copy link

还有一个关于indicator的问题,因为indicator的切换是在SCROLL_STATE_IDLE时,如果连续滑动好几个page(例如从第一页到第四页),这中间indicator一直指示的是第一页,直到第四页SCROLL_STATE_IDLE时,indicator直接切换第四页对应的位置

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

No branches or pull requests

3 participants