• Stars
    star
    177
  • Rank 215,985 (Top 5 %)
  • Language
    Java
  • License
    Apache License 2.0
  • Created over 8 years ago
  • Updated over 8 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

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

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

More Repositories

1

CardStackView

One Custom view for show something just like cards with animations.
Java
2,179
star
2

shadow

Deprecated because of the performance not fine. Android custom shadow view, can replace your CardView
Kotlin
1,371
star
3

itemtouchhelper-extension

Extension for itemtouchhelper with swipe settling,recover and no conflict with recyclerview
Java
1,040
star
4

code-reader

One Multi program language code reader
Kotlin
947
star
5

AlertTransition

AlertTransition is a extensible library for making view controller transitions, especially for alert transitions.
Swift
580
star
6

ScrollTableView

Android one demo of horizontal and vertical scroll custom table view
Java
112
star
7

ImageGroupView

Android image group view. One android custom view you can show and add image
Java
73
star
8

PullSwitcher

Help to switch fragment easier
Java
50
star
9

LoginLib

ๅฏน็™ปๅฝ•ๆณจๅ†Œไธญๅ‘้€้ชŒ่ฏ็ ๆŒ‰้’ฎๅ’ŒๆไบคๆŒ‰้’ฎ็š„ๅฐ่ฃ…ใ€‚
Java
29
star
10

MultiTextTagView

Android Multi Tag View
Java
23
star
11

quickcms

laravel quick cms
HTML
20
star
12

LPAlbum

an albums that can preview, multiple-choice
Swift
17
star
13

AutoLoopPager

One library can make pager slide loop, and add your custom view easier.
Java
17
star
14

AttributedStringWrapper

a simple packaging for NSAttributedString to make the developers easy to use
Swift
16
star
15

CoordinateLayoutDemo

Android One Test of CoordinatorLayout
Java
14
star
16

ProjectDevelopModule

Java
11
star
17

AndroidLearnNote

Some note from learning Android
Java
8
star
18

PullToRefreshAndLoadMore

Android pull to refresh, load more
Java
3
star
19

android-kotlin-ext

One library of kotlin extension functions for android
Kotlin
3
star
20

easypush

A package for push messages
PHP
2
star
21

android-plugin-loopeermodel

an Android Studio plugin for generating model using loopeer data dictionary.
Java
1
star
22

QRCodeScan

Java
1
star
23

FilterDropMenu

Java
1
star
24

bangduobao

ๅธฎๅคšๅฎ้ฆ–้กต้™ๆ€ๆ–‡ไปถ
HTML
1
star
25

LoopeerLogin

Java
1
star
26

DriveIndicator

Java
1
star