Giter VIP home page Giter VIP logo

wyvector / shswiperefreshlayout Goto Github PK

View Code? Open in Web Editor NEW

This project forked from miomin/shswiperefreshlayout

0.0 2.0 0.0 11.63 MB

Android 升级版 SwipeRefreshLayout,支持下拉刷新(Refresh)和上拉加载更多(Loadmore),支持自定义HeaderView和FooterView,支持RecyclerView、ScrollView嵌套滚动,支持任何View和Layout,支持自定义动画

License: MIT License

Java 100.00%

shswiperefreshlayout's Introduction

SHSwipeRefreshLayout by miomin

支持下拉刷新和上拉加载更多,支持自定义HeaderView和FooterView,支持RecyclerView、ScrollView嵌套滚动,支持所有Layout,支持自定义动画


如果有帮助,记得右上角的Star一下哟(https://github.com/miomin/SHSwipeRefreshLayout)


简介

gif

  • 使用方法与Google的SwipeRefreshLayout一致,采用内包裹的方式
  • 支持下拉刷新和上拉加载更多
  • 支持通过Resource ID或View自定义HeaderView和FooterView的样式
  • 通过NestedScrolling支持RecyclerView和ScrollView的嵌套滚动不收影响
  • 支持所有Layout、View
  • 支持在回调中设置自定义动画
  • 可以同时支持下拉刷新和上拉加载中的其中一个

How to use

In XML

<com.scu.miomin.shswiperefresh.core.SHSwipeRefreshLayout
        android:id="@+id/swipeRefreshLayout"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:load_text="加载更多"
        app:progress_bar_color="@color/colorPrimary"
        app:refresh_text="下拉刷新"
        app:guidance_text_color="@color/colorPrimary"
        app:guidance_view_bg_color="@color/transparent">

        <android.support.v7.widget.RecyclerView
            android:id="@+id/recyclerView"
            android:layout_width="match_parent"
            android:layout_height="match_parent"/>
</com.scu.miomin.shswiperefresh.core.SHSwipeRefreshLayout>

所有属性

  • Guidance视图背景颜色 :
<attr name="guidance_view_bg_color" format="color|reference" /> 
  • Guidance视图中文字颜色 :
<attr name="guidance_text_color" format="color|reference" /> 
  • 进度条颜色 :
<attr name="progress_bar_color" format="color|reference" /> 
  • 进度条背景色 :
<attr name="progress_bg_color" format="color|reference" /> 
  • 下拉刷新文字描述 :
<attr name="refresh_text" format="string|reference" /> 
  • 上拉加载文字描述 :
<attr name="load_text" format="string|reference" /> 
  • 下拉刷新是否可用 :
<attr name="pull_refresh_enable" format="boolean" /> 
  • 上拉加载是否可用 :
<attr name="loadmore_enable" format="boolean" /> 

自定义HeaderView、FooterView

如果不设置,则使用默认的ProgressBar+文字

也可以这样设置 :

  • 设置Resource ID
swipeRefreshLayout.setFooterView(R.layout.refresh_view);
  • 设置View
swipeRefreshLayout.setFooterView(myview);

监听器

  
        swipeRefreshLayout.setOnRefreshListener(new SHSwipeRefreshLayout.SHSOnRefreshListener() {
               @Override
               public void onRefresh() {
                   swipeRefreshLayout.postDelayed(new Runnable() {
                       @Override
                       public void run() {
                           swipeRefreshLayout.finishRefresh();
                           Toast.makeText(MainActivity.this, "刷新完成", Toast.LENGTH_SHORT).show();
                       }
                   }, 1600);
               }
   
               @Override
               public void onLoading() {
                   swipeRefreshLayout.postDelayed(new Runnable() {
                       @Override
                       public void run() {
                           swipeRefreshLayout.finishLoadmore();
                           Toast.makeText(MainActivity.this, "加载完成", Toast.LENGTH_SHORT).show();
                       }
                   }, 1600);
               }
   
               /**
                * 监听下拉刷新过程中的状态改变
                * @param percent 当前下拉距离的百分比(0-1)
                * @param state 分三种状态{NOT_OVER_TRIGGER_POINT:还未到触发下拉刷新的距离;OVER_TRIGGER_POINT:已经到触发下拉刷新的距离;START:正在下拉刷新}
                */
               @Override
               public void onRefreshPulStateChange(float percent, int state) {
                   switch (state) {
                       case SHSwipeRefreshLayout.NOT_OVER_TRIGGER_POINT:
                           swipeRefreshLayout.setLoaderViewText("下拉刷新");
                           break;
                       case SHSwipeRefreshLayout.OVER_TRIGGER_POINT:
                           swipeRefreshLayout.setLoaderViewText("松开刷新");
                           break;
                       case SHSwipeRefreshLayout.START:
                           swipeRefreshLayout.setLoaderViewText("正在刷新");
                           break;
                   }
               }
   
               @Override
               public void onLoadmorePullStateChange(float percent, int state) {
                   switch (state) {
                       case SHSwipeRefreshLayout.NOT_OVER_TRIGGER_POINT:
                           textView.setText("上拉加载");
                           break;
                       case SHSwipeRefreshLayout.OVER_TRIGGER_POINT:
                           textView.setText("松开加载");
                           break;
                       case SHSwipeRefreshLayout.START:
                           textView.setText("正在加载...");
                           break;
                   }
               }
           });
       }
 
  • 可以在onRefreshPulStateChange和onLoadmorePullStateChange中,根据参数值来做一些自定义动画

其他

  • 结束下拉刷新
  
  swipeRefreshLayout.finishRefresh();
 
  • 结束上拉加载
  
  swipeRefreshLayout.finishLoadmore();
 

License

The MIT License (MIT)

Copyright (c) 2016 莫绪旻

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

shswiperefreshlayout's People

Contributors

miomin avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.