Coder Social home page Coder Social logo

yzw20110902 / easypulllayout Goto Github PK

View Code? Open in Web Editor NEW

This project forked from huzenan/easypulllayout

0.0 1.0 0.0 11.41 MB

A light Pull to Refresh Layout that support both VERTICAL and HORIZONTAL.

License: Apache License 2.0

Java 4.37% Kotlin 95.63%

easypulllayout's Introduction

EasyPullLayout

A light Pull Layout for Android that support both VERTICAL and HORIZONTAL. You can wrap any layout you want to support the pulling action.

Java Demo

See EasyPullLayoutJavaDemo.

ScreenShots

RecyclerView

recyclerview

ListView

listview

ViewPager

viewpager

Fixed

fixed

Nested

nested

Usage

Add to your root build.gradle:

allprojects {
    repositories {
        ...
        maven { url 'https://jitpack.io' }
    }
}

Add the dependency:

dependencies {
    compile 'com.github.huzenan:EasyPullLayout:v1.0.0'
}

layout

Just wrap any layout with EasyPullLayout, then set the 'layout_type' attributes to 'content', 'edge_left', 'edge_top', 'edge_right' or 'edge_bottom':

<com.hzn.lib.EasyPullLayout
    android:id="@+id/epl"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:max_offset_bottom="150dp"
    app:max_offset_top="150dp"
    app:trigger_offset_bottom="75dp"
    app:trigger_offset_top="75dp">

    <com.hzn.easypulllayout.recyclerview.TransformerView
        android:id="@+id/topView"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:layout_type="edge_top" />

    <com.hzn.easypulllayout.recyclerview.TransformerView
        android:id="@+id/bottomView"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:layout_type="edge_bottom" />

    <android.support.v7.widget.RecyclerView
        android:id="@+id/rv"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_type="content" />
</com.hzn.lib.EasyPullLayout>

Activity

Then set listeners:

    // set Pull Listener if you have to change the edge view while pulling
    epl.setOnPullListener { type, fraction, changed ->
        when (type) {
            EasyPullLayout.TYPE_EDGE_TOP -> {
                topView.setFraction(START_FRACTION, fraction)
                if (fraction == 1f)
                    topView.ready()
                else
                    topView.idle()
            }
            ...
        }
    }
    // set Trigger Listener, do your actions while the edge view is triggered
    epl.setOnTriggerListener {
        when (it) {
            EasyPullLayout.TYPE_EDGE_TOP -> {
                topView.triggered()
            }
            EasyPullLayout.TYPE_EDGE_BOTTOM -> {
                bottomView.triggered()
            }
            Loading()
        }
    }

Also if you want to check the edge yourself, set the Edge Listener(this will cover the default checking process):

    epl.setOnEdgeListener {
        ...
        if (onEdge)
            return EasyPullLayout.TYPE_EDGE_TOP
        ...
    }

LayoutParams

name description
layout_type content, edge_left, edge_top, edge_right or edge_bottom

Attributes

name description
trigger_offset_left the triggered offset on left side
trigger_offset_top the triggered offset on top side
trigger_offset_right the triggered offset on right side
trigger_offset_bottom the triggered offset on bottom side
max_offset_left the max offset on left side
max_offset_top the max offset on top side
max_offset_right the max offset on right side
max_offset_bottom the max offset on bottom side
fixed_content_left true if left edge is in content fixed mode
fixed_content_top true if top edge is in content fixed mode
fixed_content_right true if right edge is in content fixed mode
fixed_content_bottom true if bottom edge is in content fixed mode
roll_back_duration the duration while the edge view rolling back
sticky_factor 0f~1f, default 0.66f, the factor that decide how sticky while pulling

easypulllayout's People

Contributors

huzenan avatar

Watchers

James Cloos 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.