前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >PullToRefreshLayout

PullToRefreshLayout

作者头像
用户3004328
发布2018-09-06 17:17:04
4820
发布2018-09-06 17:17:04
举报
文章被收录于专栏:增长技术

Pull Refresh Layout Library , If you have any question or suggestion with this library , welcome to tell me !

Introduction

PullToRefreshLayout是一个用法同系统SwipeRefreshLayout可灵活自定义下拉刷新、上拉加载视图的Android库.

Demo

Usage

Step 1

Add this in your root build.gradle file (not your module build.gradle file):

代码语言:javascript
复制
allprojects {
	repositories {
		...

		maven { url "https://jitpack.io" }
	}
}
Dependency

Add this to your module’s build.gradle file:

代码语言:javascript
复制
dependencies {
    ...

	compile 'com.github.changjiashuai:PullToRefreshLayout:v1.0.1'
    ...
}

Step 2

Add the PullToRefreshLayout to your layout:

Simple

代码语言:javascript
复制
    <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>

Step 3

It’s very simple use just like .

代码语言:javascript
复制
   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);//替换默认上拉加载视图

Custom HeaderView and FooterView

See HeaderView, FooterView in pulltorefresh.

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2016-10-21,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • Introduction
  • Demo
  • Usage
    • Step 1
      • Dependency
    • Step 2
      • Step 3
      • Custom HeaderView and FooterView
      领券
      问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档