Giter Club home page Giter Club logo

learn-ptrheader's Introduction

PtrMDHeader

##用来干什么? What is it used for? 给用户下拉刷新的操作带来更好的视觉体验
For bringing a better visual experience when pull to refresh

##如何去使用 How to use 基于开源框架 android-Ultra-Pull-To-Refresh
在build.gradle中:

compile 'in.srain.cube:ultra-ptr:1.0.11'

image

在xml中:within xml

<in.srain.cube.views.ptr.PtrFrameLayout
    android:id="@+id/lay_ptr_frame"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <LinearLayout
        android:id="@+id/store_house_ptr_image_content"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="#FFFFFF"
        android:gravity="center_horizontal">
        
    </LinearLayout>
</in.srain.cube.views.ptr.PtrFrameLayout>

为了达到这样的效果,仅仅需要在activity中: in order to get the wanted effect, you need open the activity:

storeHousePtrImageContent = findViewById(R.id.store_house_ptr_image_content);
layPtrFrame = (PtrFrameLayout) findViewById(R.id.lay_ptr_frame);
final PtrMDHeader header = new PtrMDHeader(getContext());
layPtrFrame.setHeaderView(header);
layPtrFrame.addPtrUIHandler(header);
layPtrFrame.setPtrHandler(new PtrHandler() {
    @Override
    public boolean checkCanDoRefresh(PtrFrameLayout frame, View content, View header) {
        return PtrDefaultHandler.checkContentCanBePulledDown(frame, storeHousePtrImageContent, header);
    }

    @Override
    public void onRefreshBegin(final PtrFrameLayout frame) {
        postDelayed(new Runnable() {
            @Override
            public void run() {
                // 模仿延时3000毫秒
                boolean refreshResult = false;
                header.refreshComplete(refreshResult, frame);
            }
        }, 3000);
    }
});

改变 refreshResult 的值来分别显示刷新成功和刷新失败的结果。 代码刷新成功和刷新失败使用了图片素材 ptr_header_md_fail.pngptr_header_md_success.png,替换素材可以显示不一样的效果。

##更加详细的源码分析和实现思路讲解 请戳这里

##感激 Appreciation 感谢这些朋友 Gratitude to all friends involved

##其它 Others 希望你喜欢我的作品。Star是对我的最大支持. 谢谢

hope you like my work. Star support me a lot. thanks

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.