hanhailong / gridpagersnaphelper Goto Github PK
View Code? Open in Web Editor NEWA powerful tools to impl grid paging layout by RecyclerView
License: Apache License 2.0
A powerful tools to impl grid paging layout by RecyclerView
License: Apache License 2.0
假如设置如下:
GridPagerSnapHelper gridPagerSnapHelper = new GridPagerSnapHelper();
gridPagerSnapHelper.setRow(3).setColumn(4);
gridPagerSnapHelper.attachToRecyclerView(mRecyclerView);
这时候,如果mRecyclerView的itemCount不是3*4的整数倍(例如36),则最后一页划不过去
在使用过程中发现,底部的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的位置正确,以上问题得到解决。
如题,虽然不影响使用
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.