Giter Club home page Giter Club logo

pulltorefresh's Introduction

PullToRefresh

开发者可以使用 PullToRefresh 对各种控件实现下拉刷新或者上拉加载以及可以自定义刷新和加载部分的视图。

目前支持:ScrollView ListViewWebViewRecyclerView

版本记录

v1.0.3

修复了滑动最小距离判断

v1.1.0

新增了空数据,加载中以及网络错误的3种状态页面

v1.2.0

1、修复了ypf168326 issue 并添加了例子 2、修复了刷新加载期间不能滑动的问题

v1.2.5

新增自定义不用每次都设置头部和底部demo

v1.2.6

1、fix bug
2、新增自动刷新(autoRefresh),禁止刷新(canRefresh)

v1.2.7

1、fix issue#9

效果图

基本用法

1、添加 Gradle 依赖

目前只支持 Android Studio

compile 'com.jwenfeng.pulltorefresh:library:1.2.7'

2、布局文件

注意:内容控件 有且只能有一个,目前支持:ScrollView ListViewWebViewRecyclerView

<?xml version="1.0" encoding="utf-8"?>
<com.jwenfeng.library.pulltorefresh.PullToRefreshLayout 
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/activity_main"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    
    <!-- 内容控件 有且只能有一个 -->
     <ScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent">
    
     </ScrollView>
    
</com.jwenfeng.library.pulltorefresh.PullToRefreshLayout>
    

3、在Activity或者Fragment中使用

pullToRefreshLayout.setRefreshListener(new BaseRefreshListener() {
            @Override
            public void refresh() {
                new Handler().postDelayed(new Runnable() {
                    @Override
                    public void run() {
                        // 结束刷新
                        pullToRefreshLayout.finishRefresh();
                    }
                }, 2000);
            }

            @Override
            public void loadMore() {
                new Handler().postDelayed(new Runnable() {
                    @Override
                    public void run() {
                        // 结束加载更多
                        pullToRefreshLayout.finishLoadMore();
                    }
                }, 2000);
            }
        });

4、自定义视图

自定义下拉刷新视图需要实现 HeadView 接口

public interface HeadView {

    /**
     * 开始下拉
     */
    void begin();

    /**
     * 回调的精度,单位为px
     *
     * @param progress 当前高度
     * @param all      总高度
     */
    void progress(float progress, float all);

    void finishing(float progress, float all);
    /**
     * 下拉完毕
     */
    void loading();

    /**
     * 看不见的状态
     */
    void normal();

    /**
     * 返回当前视图
     * */
    View getView();

}

具体请参考Demo中 HeadRefreshView

上拉加载更多用法和下拉刷新类似,具体参考 LoadMoreView.java

不用每次都设置头部和底部啦,可以继承PullToRefreshLayout,具体参考 NormalPullToRefreshLayout

5、其他

可以设置下拉刷新和上拉加载控件的高度和拉取的最大高度,默认为60dp,最大拉取为120dp,可自行设置。

6、v1.1.0 新增自定义3中状态页面

截图

用法

XML
<com.jwenfeng.library.pulltorefresh.PullToRefreshLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/activity_recycler_view"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:view_error="@layout/layout_error"
    app:view_empty="@layout/layout_empty"
    app:view_loading="@layout/layout_loading">

</com.jwenfeng.library.pulltorefresh.PullToRefreshLayout>

app:view_error 网络错误页面

app:view_empty 空数据页面

app:view_loading 加载中页面

该三个属性可以不填写,默认样式为上图所示,可以自定义

java用法
pullToRefreshLayout.showView(ViewStatus.LOADING_STATUS);

设置需要显示的视图

// 获取页面
View error = pullToRefreshLayout.getView(ViewStatus.ERROR_STATUS);

获取所需要的视图view

注意 一定要在调用了设置相应的视图之后才可以调用获取页面,否则view为空

License

Copyright 2016-2017 jinwenfeng

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.

pulltorefresh's People

Contributors

823546371 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

pulltorefresh's Issues

如果下拉刷新到底部的tab再松开,顶部一直会停留在“松开刷新”的状态

如果下拉刷新到底部的tab再松开,顶部一直会停留在“松开刷新”的状态。
大体的布局是:
《com.jwenfeng.library.pulltorefresh.PullToRefreshLayout》
《RecyclerView》
《/RecyclerView》
《/com.jwenfeng.library.pulltorefresh.PullToRefreshLayout》

《RadioGroup》
这儿是几个RadioButton...(下拉PullToRefreshLayout到这个位置再松开,会有问题,一直停留在"松开刷新")
《/RadioGroup》

配合X5WebView使用不行

本人使用的不是系统默认的webview,是腾讯tbs的webview,发现在页面上拉浏览下面的页面,在返回到顶部的时候,直接触发了下拉刷新(此时还停留在页面中间),是不是你的控件高度判断有问题?

【bug】1.2.6 设置自己的headview,然后刷新报错。

原因是因为 你setHeadView只是把成员变量进行了赋值而已,并没有执行addHeadView的方法,所以,现在的这个custom headview没有layoutParams , onTouchEvent里面 你又用到了 layoutparam.height,直接空指针!

1723b541-0d24-4ddd-80a2-6ec60022af43

4ae911ea-83f0-4eb7-83cb-4c98c48f4076

Support creation by code

The layout can only be inflated from xml because some critical initialization is performed in onFinishInflate()

@Override
protected void onFinishInflate() {
    super.onFinishInflate();
    mChildView = getChildAt(0);
    addHeadView();
    addFooterView();
}

When I create the view hierarchy by code, for example, in anko layout DSL, it ends up with NullPointerException because mChild is never set.

Hopefully it's an easy fix :)

国际化

请问可以设置语言国际化吗?

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.