• Stars
    star
    249
  • Rank 162,987 (Top 4 %)
  • Language
    Java
  • License
    Apache License 2.0
  • Created over 7 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A powerful tools to impl grid paging layout by RecyclerView

Download Build Status

GridPagerSnapHelper

A powerful tools to impl grid paging layout by RecyclerView,support horizontal and vertical page

效果图

vertical orientation

带有Indicator的

Download

Jcenter(Recommend)

 compile 'com.hhl:gridpagersnaphelper:1.0.0'

 // Optional , config indicator
 compile 'com.hhl:recyclerviewindicator:1.0.0'

Maven

<dependency>
  <groupId>com.hhl</groupId>
  <artifactId>gridpagersnaphelper</artifactId>
  <version>1.0.0</version>
  <type>pom</type>
</dependency>

// Optional , config indicator

<dependency>
  <groupId>com.hhl</groupId>
  <artifactId>recyclerviewindicator</artifactId>
  <version>1.0.0</version>
  <type>pom</type>
</dependency>

Usage:

for example:

RecyclerView recyclerView = (RecyclerView) findViewById(R.id.recycler_view);
recyclerView.setHasFixedSize(true);

//setLayoutManager
GridLayoutManager gridLayoutManager = new GridLayoutManager(this, row, LinearLayoutManager.HORIZONTAL, false);
recyclerView.setLayoutManager(gridLayoutManager);

//attachToRecyclerView
GridPagerSnapHelper gridPagerSnapHelper = new GridPagerSnapHelper();
gridPagerSnapHelper.setRow(row).setColumn(column);
gridPagerSnapHelper.attachToRecyclerView(recyclerView);

int screenWidth = ScreenUtils.getScreenWidth(this);
int itemWidth = screenWidth / column;

//transform data list
List<DataSourceUtils.ItemData> dataList = DataSourceUtils.getDataSource();
dataList = GridPagerUtils.transformAndFillEmptyData(
        new OneRowDataTransform<DataSourceUtils.ItemData>(column), dataList);

//setAdapter
RecyclerViewAdapter adapter = new RecyclerViewAdapter(this, dataList, itemWidth);
recyclerView.setAdapter(adapter);

//indicator
CirclePageIndicator indicator = (CirclePageIndicator) findViewById(R.id.first_page_indicator);
indicator.setRecyclerView(firstRV);
//Note: pageColumn must be config
indicator.setPageColumn(column);

indicator.setOnPageChangeListener(new OnPageChangeListener() {
    @Override
    public void onPageSelected(int position) {

    }

    @Override
    public void onPageScrollStateChanged(int state) {

    }
});

Step 1. setLayoutManager:

You'd better set a horizontal direction GridLayoutManager

Step 2. RecyclerView attach to GridPagerSnaperHelper

GridPagerSnapHelper gridPagerSnapHelper = new GridPagerSnapHelper();
gridPagerSnapHelper.setRow(row).setColumn(column);
gridPagerSnapHelper.attachToRecyclerView(recyclerView);

Here,you must set row and column

Step 3. transform data list

if your src data is dataList,you must transform it to dst data

GridPagerUtils.transformAndFillEmptyData(
        new OneRowDataTransform<DataSourceUtils.ItemData>(column), dataList);

Here,I have provided three transform order functions

  1. OneRowDataTransform

    mapping one row,n column

  2. TwoRowDataTransform

    mapping two row,n column

  3. ThreeRowDataTransform

    mapping three row,n column

You can impl your custom row funcitons by extends AbsRowDataTransform

Step4. (Optional) Config Indicator

CirclePageIndicator indicator = (CirclePageIndicator) findViewById(R.id.first_page_indicator);
indicator.setRecyclerView(firstRV);
//Note: pageColumn must be config
indicator.setPageColumn(column);

indicator.setOnPageChangeListener(new OnPageChangeListener() {
    @Override
    public void onPageSelected(int position) {

    }

    @Override
    public void onPageScrollStateChanged(int state) {

    }
});

Why use AbsRowDataTransform?

In general,horizontal direction GridLayoutManager layout like this:

But,We want is the following case :

so,We need to make a transformation of the data.Here,AbsRowDataTransform can meet your needs.

Author

hanhailong worked in 58同城,A fantastic website

[email protected]

More Repositories

1

FlowTag

Android流式布局,支持点击、单选、多选,支持初始化选中标签(只针对单选和多选模式),适合用于产品标签等,用法采用Adapter模式,和ListView、GridView用法一样!!!
Java
896
star
2

tubatu-viewpager

高仿土巴兔选择装修风格的效果,这里通过自定义ViewPager来实现,为什么通过ViewPager来实现呢,一是ViewPager很容易实现切换动画效果,二是选择的那一项自动居中
Java
278
star
3

VCL-Android

编译好的VCL-Android版本,打了四种架构的so包,armeabi-v7a、armeabi、x86、mips
Java
239
star
4

sina-popmenu

高仿新浪微博弹框菜单
Java
200
star
5

SwipeBackSample

高仿微信手势滑动返回
Java
174
star
6

tubatu-iCarousel

高仿土巴兔选择装修风格的效果,这里通过自定义iCarousel来实现,为什么通过iCarousel来实现呢,一是iCarousel很容易实现切换动画效果,二是选择的那一项自动居中
Objective-C
85
star
7

AndroidStudyResources

整理的Android学习资源,不定期的更新
Java
63
star
8

CustomRatingBar

自定义的IOS星级评分条,支持点击选中,支持滑动选择,直接选中半颗星
Objective-C
56
star
9

TwoBallRotationProgressBar

两个小球旋转的动画,一个清新的进度条
Java
39
star
10

base-adapter-helper-recyclerview

基于base-adapter-helper改造用来支持recyclerview的适配器
Java
31
star
11

Coding-StartGuidePage-01

IOS开源Coding客户端学习——(一)启动引导页面
Objective-C
26
star
12

IOSSwitchView

高仿IOS风格的UISwitch控件
Java
21
star
13

SlidingMenuSwipeBackDemo

Java
19
star
14

DevHeadLine

高仿开发者头条
Java
14
star
15

LagoApp_RN

通过react-native来高仿的拉勾招聘app
JavaScript
13
star
16

TwoBallRotationProgressBar-IOS

IOS版本的两个小球绕中心旋转的进度条,可设置颜色、小球半径、旋转半径和动画时间等等
Objective-C
13
star
17

ijkmediaplayer

AndroidStudio编译完成的ijkmediaplayer库
Python
9
star
18

ReactNativeProject

因项目需要,最近两天研究RN,这里介绍已经存在的一个项目是如何移植RN的
Java
7
star
19

ijkmediaplayer-ios

IOS版本编译好的ijkmediaplayer库
C
7
star
20

HeaderFooterGridView

像ListView一样给GridView添加Header和Footer,目前只添加了Header,后续完善中....
Java
4
star
21

HHLAndroidProject

一个包含所有Android知识点的综合项目,里面包含封装好的网络库、缓存、图片加载等等
Java
4
star
22

HHLInfiniteScrollBanner

使用UICollectionView来实现无限滚动的Banner视图
Objective-C
3
star
23

IOSStudyResource

IOS学习资源整理,不定期的更新
3
star
24

VCL-Official

最新官方1.8.0版本的VCL,目前只编译的armv7和x86架构的,如果需要其他架构的,请联系我
Java
2
star
25

CompileAnnotationDemo

Android中编译时注解实际运行Demo,仿照ButterKnife来写的
Java
1
star
26

OpenGLES_Tutorial_Android

A practice project for OpenGL ES
Kotlin
1
star
27

AlgorithmStudy

A project about algorithm
Java
1
star
28

E2CTranstions

English to Chinese in IntelliJ IDEA or AndroidStudio
Java
1
star
29

CommonUtil

常用的工具类、命令、方法整理
1
star
30

ZxingMake

Through the use of Android Studio to compile the library of zxing
C++
1
star