運作截圖

基于 PagerSnapHelper 自定義 GridPagerSnapHelper.
支援橫向與縱向滑動,行列數量可自定義傳入
private void initGridePager() {
// 3行3列,橫向
int colum = 3;
int row = 3;
int orientation = GridLayoutManager.HORIZONTAL;
int spanCount = (GridLayoutManager.VERTICAL == orientation) ? colum : row;
// 設定布局管理器
GridLayoutManager gridLayoutManager = new GridLayoutManager(getApplicationContext(), spanCount, orientation, false);
mRecyclerView.setLayoutManager(gridLayoutManager);
// 設定設配器
GridPagerAdapter gridPagerAdapter = new GridPagerAdapter(getApplicationContext(), orientation, colum, row);
mRecyclerView.setAdapter(gridPagerAdapter);
// 設定頁面滑動幫助類 sanaphelp
GridPagerSnapHelper pagerSnapHelper = new GridPagerSnapHelper(colum, row);
pagerSnapHelper.attachToRecyclerView(mRecyclerView);
}
demo位址:
https://github.com/PPQingZhao/GridPagerDemo