Step 1. Add the JitPack repository to your build file
Add it in your root settings.gradle at the end of repositories:
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
mavenCentral()
maven { url 'https://jitpack.io' }
}
}
Add it in your settings.gradle.kts at the end of repositories:
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
mavenCentral()
maven { url = uri("https://jitpack.io") }
}
}
Add to pom.xml
<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>
Add it in your build.sbt at the end of resolvers:
resolvers += "jitpack" at "https://jitpack.io"
Add it in your project.clj at the end of repositories:
:repositories [["jitpack" "https://jitpack.io"]]
Step 2. Add the dependency
dependencies {
implementation 'com.github.changjiashuai:PullToRefreshLayout:v1.0.2'
}
dependencies {
implementation("com.github.changjiashuai:PullToRefreshLayout:v1.0.2")
}
<dependency>
<groupId>com.github.changjiashuai</groupId>
<artifactId>PullToRefreshLayout</artifactId>
<version>v1.0.2</version>
</dependency>
libraryDependencies += "com.github.changjiashuai" % "PullToRefreshLayout" % "v1.0.2"
:dependencies [[com.github.changjiashuai/PullToRefreshLayout "v1.0.2"]]
===================
Pull Refresh Layout Library , If you have any question or suggestion with this library , welcome to tell me !
PullToRefreshLayout
是一个用法同系统SwipeRefreshLayout
可灵活自定义下拉刷新、上拉加载视图的Android库.
Add this in your root
build.gradle
file (not your modulebuild.gradle
file):
allprojects {
repositories {
...
maven { url "https://jitpack.io" }
}
}
Add this to your module's
build.gradle
file:
dependencies {
...
compile 'com.github.changjiashuai:PullToRefreshLayout:$lastversion'
...
}
Add the PullToRefreshLayout to your layout:
Simple
<io.github.changjiashuai.pulltorefresh.PullToRefreshLayout
android:id="@+id/pullToRefreshLayout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.RecyclerView
android:id="@+id/recyclerView"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</io.github.changjiashuai.pulltorefresh.PullToRefreshLayout>
<!--app:headerView、app:footerView 设置布局视图-->
<io.github.changjiashuai.pulltorefresh.PullToRefreshLayout
android:id="@+id/pullToRefreshLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:headerView="@layout/refresh_view"
app:footerView="@layout/pull_view">
<android.support.v7.widget.RecyclerView
android:id="@+id/recyclerView"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</io.github.changjiashuai.pulltorefresh.PullToRefreshLayout>
It's very simple use just like .
mRecyclerView = (RecyclerView) findViewById(R.id.recyclerView);
mPullToRefreshLayout = (PullToRefreshLayout) findViewById(R.id.pullToRefreshLayout);
mPullToRefreshLayout.setOnRefreshListener(new PullToRefreshLayout.OnRefreshListener() {
@Override
public void onRefresh() {
Log.i(TAG, "onRefresh: ");
mRecyclerView.postDelayed(new Runnable() {
@Override
public void run() {
mAdapter.setStrings(initData());
mPullToRefreshLayout.endRefresh();
}
}, 1000);
}
});
mPullToRefreshLayout.setOnLoadMoreListener(new PullToRefreshLayout.OnLoadMoreListener() {
@Override
public void onLoadMore() {
Log.i(TAG, "onLoadMore: ");
mRecyclerView.postDelayed(new Runnable() {
@Override
public void run() {
mAdapter.insert(addData());
mPullToRefreshLayout.endLoadMore();
}
}, 1000);
}
});
mRecyclerView.postDelayed(new Runnable() {
@Override
public void run() {
mPullToRefreshLayout.autoRefresh();
}
}, 500);
//可选设置
mPullToRefreshLayout.setHeaderHeight(200);//设置刷新视图刷新时高度, 可滑动高度是这个的2倍
mPullToRefreshLayout.setFooterHeight(200);//设置上拉视图加载时高度, 可滑动高度是这个的2倍
mPullToRefreshLayout.setCanRefresh(false);//设置是否开启下拉刷新功能
mPullToRefreshLayout.setCanLoadMore(false);//设置是否开启上拉加载功能
// 默认使用 HeaderView FooterView --> 可自定义支持任意View
mPullToRefreshLayout.setHeaderView(mHeaderView);//替换默认下拉刷新视图
mPullToRefreshLayout.setFooterView(mFooterView);//替换默认上拉加载视图
See HeaderView, FooterView in pulltorefresh.
##Contact me
If you have a better idea or way on this project, please let me know, thanks :)
Copyright 2016 changjiashuai
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.