Git Product home page Git Product logo

android-simple-common-pulltorefreshlayout's Introduction

Android-Simple-Common-PullToRefreshLayout

This is a light-weight Android PullToRefreshLayout, can be applied to any scrollable view.
这是一个轻量级的Android下拉刷新控件,可以应用在任何可滚动的View 当中。 #Effect:

Feature

Light-weight 轻量级

This Widget only have a class file(PullToRefreshLayout.java). You can just copy it in to your project! So easy!
这个组件只有一个类(PullToRefreshLayout.java),你可以将这个文件复制到项目当中就可用了。

Custom refresh view 顶部刷新的View可以自定义

  • custom animation 自定义动画
    PullToRefreshLayout provides 3 interface method.
    public interface OnRefreshListener {
        void onRefresh();
        
        void onFinish();

        void onDragDistanceChange(float distance, float percent, float offset);
    }

void onDragDistanceChange(float distance, float percent, float offset);This method can be used to create custom animation with your refresh view.
用onDragDistanceChange()该方法可以自定义RefreshView 的动画;

        mPullToRefreshView.setOnRefreshListener(new PullToRefreshLayout.OnRefreshListenerAdapter() {
            @Override
            public void onRefresh() {
                textView.setText("正在刷新");
                Log.d("TAG", "onRefresh() called with: " + "");
                imgDone.setVisibility(View.GONE);
                imageView.setVisibility(View.INVISIBLE);
                progressBar.setVisibility(View.VISIBLE);
                mPullToRefreshView.postDelayed(new Runnable() {
                    @Override
                    public void run() {
                        mPullToRefreshView.setRefreshing(false);
//                        progressBar.setVisibility(View.GONE);
                    }
                }, 2000);
            }

            @TargetApi(Build.VERSION_CODES.HONEYCOMB)
            @Override
            public void onDragDistanceChange(float distance, float percent, float offset) {
                if (percent >= 1.0f) {
                    textView.setText("松开刷新");
                    imgDone.setVisibility(View.GONE);
                    imageView.setVisibility(View.VISIBLE);
                    imageView.setRotation(180);
                } else {
                    textView.setText("下拉刷新");
                    imgDone.setVisibility(View.GONE);
                    imageView.setVisibility(View.VISIBLE);
                    imageView.setRotation(0);
                }
            }
            @Override
            public void onFinish() {
                textView.setText("刷新成功");
                imageView.setVisibility(View.GONE);
                progressBar.setVisibility(View.GONE);
                imgDone.setVisibility(View.VISIBLE);
            }
        });
  • custom view with layout xml just like this:
    private View createRefreshView() {
        mPullToRefreshView = (PullToRefreshLayout) rootView.findViewById(R.id.pull_to_refresh);
        View headerView=mPullToRefreshView.setRefreshView(R.layout.layout_head);
        progressBar = (ProgressBar) headerView.findViewById(R.id.pb_view);
        textView = (TextView) headerView.findViewById(R.id.text_view);
        textView.setText("下拉刷新");
        imageView = (ImageView) headerView.findViewById(R.id.image_view);
        imageView.setVisibility(View.VISIBLE);
        imageView.setImageResource(R.drawable.down_arrow);
        imgDone=(ImageView)headerView.findViewById(R.id.img_done);
        imgDone.setImageResource(R.drawable.ic_check_circle_black);
        imgDone.setVisibility(View.GONE);
        progressBar.setVisibility(View.GONE);
        return headerView;
    }

Readable source code 源码易读性高

添加了非常详细的中文注释

Support control by code to do refresh 支持代码控制自动刷新

when finishing refresh, the time to stick the refresh view can be set;

可以控制Refresh view在刷新完成后停留的时间 just like:

        mPullToRefreshView.setFinishRefreshToPauseDuration(800);

#Usage:

    <com.tellh.android_simple_common_pulltorefreshlayout.PullToRefreshLayout
        android:id="@+id/pull_to_refresh"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
        
        <!-- you can put any scrollable view here!-->
        <ListView
            android:id="@+id/list_view"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:divider="@null"
            android:dividerHeight="0dp"
            android:fadingEdge="none"/>

    </com.tellh.android_simple_common_pulltorefreshlayout.PullToRefreshLayout>

Enjoy it!

android-simple-common-pulltorefreshlayout's People

Contributors

tellh avatar

Watchers

 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.