SHSwipeRefreshLayout 使用教程
SHSwipeRefreshLayoutAndroid 升级版 SwipeRefreshLayout,支持RecyclerView、ScrollView等大部分组件,下拉刷新(Refresh)和上拉加载(Loadmore),支持自定义HeaderView和FooterView项目地址:https://gitcode.com/gh_mirrors/sh/SHSwipeRefreshLayout
1. 项目的目录结构及介绍
SHSwipeRefreshLayout 是一个开源的下拉刷新库,其目录结构如下:
SHSwipeRefreshLayout/
├── app/
│ ├── build.gradle
│ ├── src/
│ │ ├── main/
│ │ │ ├── java/
│ │ │ │ └── com.shizhefei.test/
│ │ │ │ └── MainActivity.java
│ │ │ ├── res/
│ │ │ │ ├── layout/
│ │ │ │ │ └── activity_main.xml
│ │ │ │ └── values/
│ │ │ │ └── strings.xml
│ ├── build/
│ └── libs/
├── library/
│ ├── build.gradle
│ ├── src/
│ │ ├── main/
│ │ │ ├── java/
│ │ │ │ └── com.shizhefei.view.refresh/
│ │ │ │ ├── OnRefreshListener.java
│ │ │ │ └── SwipeRefreshLayout.java
│ │ │ ├── res/
│ │ │ │ ├── drawable/
│ │ │ │ │ └── ic_launcher.png
│ │ │ │ └── values/
│ │ │ │ └── attrs.xml
│ ├── build/
│ └── libs/
├── build.gradle
├── gradle.properties
├── settings.gradle
└── README.md
目录结构介绍
app/
:示例应用程序的目录,包含 MainActivity 和相关资源文件。library/
:核心库的目录,包含 SwipeRefreshLayout 和相关资源文件。build.gradle
:项目的构建脚本。gradle.properties
:Gradle 配置文件。settings.gradle
:项目设置文件。README.md
:项目说明文档。
2. 项目的启动文件介绍
项目的启动文件是 MainActivity.java
,位于 app/src/main/java/com.shizhefei.test/
目录下。
package com.shizhefei.test;
import android.os.Bundle;
import android.os.Handler;
import android.support.v7.app.AppCompatActivity;
import com.shizhefei.view.refresh.SwipeRefreshLayout;
public class MainActivity extends AppCompatActivity {
private SwipeRefreshLayout swipeRefreshLayout;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
swipeRefreshLayout = findViewById(R.id.swipeRefreshLayout);
swipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
@Override
public void onRefresh() {
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
swipeRefreshLayout.setRefreshing(false);
}
}, 2000);
}
});
}
}
启动文件介绍
MainActivity
:继承自 AppCompatActivity
,是应用程序的主活动。onCreate
:活动创建时调用的方法,设置布局文件并初始化 SwipeRefreshLayout
。setOnRefreshListener
:设置下拉刷新监听器,模拟刷新操作。
3. 项目的配置文件介绍
项目的配置文件主要包括 build.gradle
和 settings.gradle
。
build.gradle
// 项目级 build.gradle
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.5.0'
}
}
allprojects {
repositories {
google()
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
// 模块级 build.gradle (app 模块)
apply plugin: 'com.android.application'
android {
compileSdkVersion 29
defaultConfig {
applicationId "com.
SHSwipeRefreshLayoutAndroid 升级版 SwipeRefreshLayout,支持RecyclerView、ScrollView等大部分组件,下拉刷新(Refresh)和上拉加载(Loadmore),支持自定义HeaderView和FooterView项目地址:https://gitcode.com/gh_mirrors/sh/SHSwipeRefreshLayout