GithubHelp home page GithubHelp logo

initliu / springheader Goto Github PK

View Code? Open in Web Editor NEW

This project forked from loopeer/springheader

0.0 1.0 0.0 1.3 MB

An implementation of spring-like header (known as pull-to-refresh) that using CoordinatorLayout.

License: Apache License 2.0

Java 100.00%

springheader's Introduction

SpringHeader

An implementation of spring-like header (known as pull-to-refresh) that using CoordinatorLayout.

demo

Usage

Simple Way

Just put a com.loopeer.springheader.SimpleRefreshHeader in your CoordinatorLayout, and add the attribute app:layout_behavior="@string/dependent_view_behavior" in the scroll view to let it scroll along header.

<android.support.design.widget.CoordinatorLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".SpringHeaderActivity">

    <com.loopeer.springheader.SimpleRefreshHeader
        android:id="@+id/header"
        android:layout_width="match_parent"
        android:layout_height="48dp"
        android:background="#cccccc"/>

    <include
        layout="@layout/scroll_view"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="@string/dependent_view_behavior"/>

</android.support.design.widget.CoordinatorLayout>

Note:

You can use DependentViewBehavior on other views as well, and you can use it multiple times or not use it at all.

The reason why we don't use CoordinatorLayout.Behavior's layout dependency function is that it won't meet all our needs.

Simple Customization

SimpleRefreshHeader has three attributes textBelowThreshold, textAboveThreshold and textRefreshing. You can also set color scheme via java code.

SimpleRefreshHeader has a DefaultBehavior, the SpringHeaderBehavior. And SpringHeaderBehavior has three params behavior_originalOffset, behavior_hoveringRange and behavior_maxRange:

  • behavior_originalOffset is the original offset of header;
  • behavior_hoveringRange is the range from original offset to hovering offset;
  • behavior_maxRange is the range from original offset to max offset. SimpleRefreshHeader has a default behavior set, but if you set any of above attributes, you may also add attribute app:layout_behavior="@string/spring_header_behavior" to make it work.

Extended Way

com.loopeer.springheader.RefreshHeader is the base class for implementing your own style of refresh header.

Also you can make use of any Views to make it work, just hook it up through the SpringHeaderCallback sets on SpringHeaderBehavior:

public interface SpringHeaderCallback {
    void onScroll(int offset, float fraction);

    void onStateChanged(int newState);
}

onScroll() method is called whenever the header offset changed.

  • fraction = (currentOffset - originalOffset) / hoveringRange. fraction starts from 0, and when currentOffset equals hoveringOffset, fraction equals 1.

onStateChanged() method is called whenever the header state changed. There are four states STATE_COLLAPSED, STATE_HOVERING, STATE_DRAGGING and STATE_SETTLING.

RefreshHeader implements SpringHeaderCallback.

References

This project is mainly referencing Android Support Library, including Design Support Library and v4 Support Library. There are three class ViewOffsetBehavior, ViewOffsetHelper and MaterialProgressDrawable copied from the Android Support Library.

License

Apache License Version 2.0

springheader's People

Contributors

korhsien avatar

Watchers

 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.