Skip to content

Commit

Permalink
2017.9.25号,添加指示器,目前支持圆形和线形
Browse files Browse the repository at this point in the history
  • Loading branch information
hanhailong committed Sep 24, 2017
1 parent 2e916d1 commit 552748b
Show file tree
Hide file tree
Showing 21 changed files with 1,327 additions and 15 deletions.
22 changes: 22 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ A powerful tools to impl grid paging layout by RecyclerView

![](screenshot/recyclerview.gif)

带有Indicator的

![](screenshot/recyclerview_indicator.gif)

# Download

## JitPack
Expand Down Expand Up @@ -77,6 +81,24 @@ dataList = GridPagerUtils.transformAndFillEmptyData(
//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:**
Expand Down
1 change: 1 addition & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,5 @@ dependencies {

// compile 'com.hhl:gridpagersnaphelper:0.0.3'

compile project(':recyclerviewindicator')
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,16 @@
import com.hhl.gridpagersnaphelper.GridPagerSnapHelper;
import com.hhl.gridpagersnaphelper.GridPagerUtils;
import com.hhl.gridpagersnaphelper.transform.OneRowDataTransform;
import com.hhl.gridpagersnaphelper.transform.TwoRowDataTransform;
import com.hhl.gridpagersnaphelper.transform.ThreeRowDataTransform;
import com.hhl.gridpagersnaphelper.transform.TwoRowDataTransform;
import com.hhl.recyclerviewindicator.CirclePageIndicator;
import com.hhl.recyclerviewindicator.LinePageIndicator;
import com.hhl.recyclerviewindicator.OnPageChangeListener;

import java.util.List;

public class RecyclerViewActivity extends AppCompatActivity {

public static final int ROW = 1;
public static final int COLUMN = 5;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Expand All @@ -33,17 +33,17 @@ protected void onCreate(Bundle savedInstanceState) {
}

private void configThridRecyclerView(int row, int column) {
RecyclerView firstRV = (RecyclerView) findViewById(R.id.recycler_view_third);
firstRV.setHasFixedSize(true);
RecyclerView thridRV = (RecyclerView) findViewById(R.id.recycler_view_third);
thridRV.setHasFixedSize(true);

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

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

int screenWidth = ScreenUtils.getScreenWidth(this);
int itemWidth = screenWidth / column;
Expand All @@ -55,21 +55,39 @@ private void configThridRecyclerView(int row, int column) {

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

//indicator
LinePageIndicator indicator = (LinePageIndicator) findViewById(R.id.third_page_indicator);
indicator.setRecyclerView(thridRV);
//Note: pageColumn must be config
indicator.setPageColumn(column);

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

}

@Override
public void onPageScrollStateChanged(int state) {

}
});
}

private void configSecondRecyclerView(int row, int column) {
RecyclerView firstRV = (RecyclerView) findViewById(R.id.recycler_view_second);
firstRV.setHasFixedSize(true);
RecyclerView secondRV = (RecyclerView) findViewById(R.id.recycler_view_second);
secondRV.setHasFixedSize(true);

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

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

int screenWidth = ScreenUtils.getScreenWidth(this);
int itemWidth = screenWidth / column;
Expand All @@ -81,7 +99,25 @@ private void configSecondRecyclerView(int row, int column) {

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

//indicator
LinePageIndicator indicator = (LinePageIndicator) findViewById(R.id.second_page_indicator);
indicator.setRecyclerView(secondRV);
//Note: pageColumn must be config
indicator.setPageColumn(column);

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

}

@Override
public void onPageScrollStateChanged(int state) {

}
});
}

private void configFirstRecyclerView(int row, int column) {
Expand All @@ -108,5 +144,23 @@ private void configFirstRecyclerView(int row, int column) {
//setAdapter
RecyclerViewAdapter adapter = new RecyclerViewAdapter(this, dataList, itemWidth);
firstRV.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) {

}
});
}
}
26 changes: 26 additions & 0 deletions app/src/main/res/layout/activity_recycler_view.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
Expand All @@ -17,18 +18,43 @@
android:layout_height="wrap_content"
android:layout_marginTop="20dp" />

<com.hhl.recyclerviewindicator.CirclePageIndicator
android:id="@+id/first_page_indicator"
android:layout_width="match_parent"
android:layout_height="30dp"
android:layout_marginTop="10dp"
android:paddingBottom="5dp"
android:paddingTop="5dp"
app:fillColor="@color/colorPrimary" />

<android.support.v7.widget.RecyclerView
android:id="@+id/recycler_view_second"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp" />

<com.hhl.recyclerviewindicator.LinePageIndicator
android:id="@+id/second_page_indicator"
android:layout_width="match_parent"
android:layout_height="30dp"
android:layout_marginTop="10dp"
app:selectedColor="@color/colorAccent" />

<android.support.v7.widget.RecyclerView
android:id="@+id/recycler_view_third"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp" />

<com.hhl.recyclerviewindicator.LinePageIndicator
android:id="@+id/third_page_indicator"
android:layout_width="match_parent"
android:layout_height="30dp"
android:layout_marginTop="10dp"
android:paddingBottom="5dp"
android:paddingTop="5dp"
app:selectedColor="@color/colorAccent" />

</LinearLayout>

</ScrollView>
1 change: 1 addition & 0 deletions recyclerviewindicator/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
33 changes: 33 additions & 0 deletions recyclerviewindicator/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
apply plugin: 'com.android.library'

android {
compileSdkVersion 25
buildToolsVersion "26.0.1"

defaultConfig {
minSdkVersion 14
targetSdkVersion 25
versionCode 1
versionName "1.0"

testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"

}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:25.3.1'
testCompile 'junit:junit:4.12'

compile 'com.android.support:recyclerview-v7:25.3.1'
}
25 changes: 25 additions & 0 deletions recyclerviewindicator/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Add project specific ProGuard rules here.
# By default, the flags in this file are appended to flags specified
# in /Users/HanHailong/Library/Android/sdk/tools/proguard/proguard-android.txt
# You can edit the include path and order by changing the proguardFiles
# directive in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html

# Add any project specific keep options here:

# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}

# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable

# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.hhl.recyclerviewindicator;

import android.content.Context;
import android.support.test.InstrumentationRegistry;
import android.support.test.runner.AndroidJUnit4;

import org.junit.Test;
import org.junit.runner.RunWith;

import static org.junit.Assert.*;

/**
* Instrumentation test, which will execute on an Android device.
*
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
*/
@RunWith(AndroidJUnit4.class)
public class ExampleInstrumentedTest {
@Test
public void useAppContext() throws Exception {
// Context of the app under test.
Context appContext = InstrumentationRegistry.getTargetContext();

assertEquals("com.hhl.recyclerviewindicator.test", appContext.getPackageName());
}
}
10 changes: 10 additions & 0 deletions recyclerviewindicator/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"

package="com.hhl.recyclerviewindicator">

<application android:allowBackup="true" android:label="@string/app_name"
android:supportsRtl="true">

</application>

</manifest>
Loading

0 comments on commit 552748b

Please sign in to comment.