Giter Club home page Giter Club logo

android-pullrefreshlayout's Introduction

android-PullRefreshLayout

Android Arsenal

This component like SwipeRefreshLayout, it is more beautiful than SwipeRefreshLayout.

Demo

Screenshot

Usage

Add dependency.

dependencies {
    compile 'com.baoyz.pullrefreshlayout:library:1.2.0'
}

Use method like SwipeRefreshLayout's usage.

Use it in your layout xml.

<com.baoyz.widget.PullRefreshLayout
    android:id="@+id/swipeRefreshLayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

	<!-- ListView、ScrollView、RecyclerView、Other -->
	
</com.baoyz.widget.PullRefreshLayout>

Get instance and use it.

PullRefreshLayout layout = (PullRefreshLayout) findViewById(...);

// listen refresh event
layout.setOnRefreshListener(new PullRefreshLayout.OnRefreshListener() {
    @Override
    public void onRefresh() {
        // start refresh
    }
});

// refresh complete 
layout.setRefreshing(false);

Change the refresh style, there are five styles of use, MATERIALCIRCLESWATER_DROPRING and SMARTISAN.

In java, call setRefreshStyle method.

layout.setRefreshStyle(PullRefreshLayout.STYLE_CIRCLES);

In xml, use attributes.

<com.baoyz.widget.PullRefreshLayout
    android:id="@+id/swipeRefreshLayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
	app:refreshType="water_drop">
	
</com.baoyz.widget.PullRefreshLayout>

Change the color scheme. In java, call setColorSchemeColors method. The int array length must be 4.

layout.setColorSchemeColors(int []);

For Smartisan style, it has only one color, can call 'setColor' method, to set one color.

layout.setColor(int);

In xml, use attributes.

<com.baoyz.widget.PullRefreshLayout
    android:id="@+id/swipeRefreshLayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:refreshColors="@array/scheme_colors"
    app:refreshColor="@color/one_color">
	
</com.baoyz.widget.PullRefreshLayout>

If you do not like these styles, you can customize the refresh style.

class CustomDrawable extends RefreshDrawable{

    @Override
    public void setPercent(float percent) {
        // Percentage of the maximum distance of the drop-down refresh.
    }

    @Override
    public void setColorSchemeColors(int[] colorSchemeColors) {
        
    }

    @Override
    public void offsetTopAndBottom(int offset) {
        // Drop-down offset.
    }

    @Override
    public void start() {
        isRunning = true;
        // Refresh started, start refresh animation.
    }

    @Override
    public void stop() {
        isRunning = false;
        // Refresh completed, stop refresh animation.
    }

    @Override
    public boolean isRunning() {
        return isRunning;
    }

    @Override
    public void draw(Canvas canvas) {
        // Draw custom style.
    }

}

Call setRefreshDrawable() method to use your custom refresh drawable.

layout.setRefreshDrawable(new CustomDrawable());

Thanks

License

The MIT License (MIT)

Copyright (c) 2014 baoyongzhang

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

android-pullrefreshlayout's People

Contributors

baoyongzhang avatar xuxucode avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

android-pullrefreshlayout's Issues

Google app style.

Add an option to have only the refresh image be pulled down, and not the view inside. Like in Google's apps. only the circle is pulled down.

I would be more then happy to contribute this feature.

ColorScheme Showing Me different Colors

   int[] colors = {#FFFFFF, #AFAFAF, #838383, #000000}; I use my Color resource not HEXs
   swipeRefreshLayout.setColorSchemeColors(colors);

But whenever I use that, I get a purplish color, but what I want is a white, light grey, dark_grey and a black. Why?

Attribute "type" has already been defined

I have included the library into my project however build fails with this error Attribute "type" has already been defined. The error log references values.xml specifically <declare-styleable>. Am using android studio with gradle version 2.2.1 and gradle tools version 1.1.0. Any quick solutions is appreciated.

Could you add support for icons drawable and animation list drawable?

It would be extreamly good if we can use custom animation with your layout. Do you have possibility to use animation drawable? For instance
<animation-list android:id="@+id/selected" android:oneshot="false">
<item android:drawable="@drawable/wheel0" android:duration="50" />
...
</animation-list>

pointerIndex out of range

Fatal Exception: java.lang.IllegalArgumentException: pointerIndex out of range
at android.view.MotionEvent.nativeGetAxisValue(MotionEvent.java)
at android.view.MotionEvent.getY(MotionEvent.java:2431)
at android.support.v4.view.MotionEventCompat.getY(MotionEventCompat.java:521)
at com.baoyz.widget.PullRefreshLayout.onTouchEvent(PullRefreshLayout.java:324)
at android.view.View.dispatchTouchEvent(View.java:10920)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2810)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2512)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2812)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2527)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2812)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2527)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2812)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2527)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2812)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2527)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2812)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2527)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2812)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2527)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2812)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2527)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2812)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2527)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2812)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2527)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2812)
at android.view.ViewGroup.cancelAndClearTouchTargets(ViewGroup.java:2662)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2368)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2842)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2469)
at com.android.internal.policy.DecorView.superDispatchTouchEvent(DecorView.java:623)
at com.android.internal.policy.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1906)
at android.app.Activity.dispatchTouchEvent(Activity.java:3247)
at android.support.v7.view.WindowCallbackWrapper.dispatchTouchEvent(WindowCallbackWrapper.java:68)
at com.android.internal.policy.DecorView.dispatchTouchEvent(DecorView.java:585)
at android.view.View.dispatchPointerEvent(View.java:11149)
at android.view.ViewRootImpl$ViewPostImeInputStage.processPointerEvent(ViewRootImpl.java:5227)
at android.view.ViewRootImpl$ViewPostImeInputStage.onProcess(ViewRootImpl.java:5076)
at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:4580)
at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:4633)
at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:4599)
at android.view.ViewRootImpl$AsyncInputStage.forward(ViewRootImpl.java:4736)
at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:4607)
at android.view.ViewRootImpl$AsyncInputStage.apply(ViewRootImpl.java:4793)
at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:4580)
at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:4633)
at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:4599)
at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:4607)
at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:4580)
at android.view.ViewRootImpl.deliverInputEvent(ViewRootImpl.java:7210)
at android.view.ViewRootImpl.doProcessInputEvents(ViewRootImpl.java:7142)
at android.view.ViewRootImpl.enqueueInputEvent(ViewRootImpl.java:7103)
at android.view.ViewRootImpl$WindowInputEventReceiver.onInputEvent(ViewRootImpl.java:7321)
at android.view.InputEventReceiver.dispatchInputEvent(InputEventReceiver.java:185)
at android.os.MessageQueue.nativePollOnce(MessageQueue.java)
at android.os.MessageQueue.next(MessageQueue.java:323)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:6823)
at java.lang.reflect.Method.invoke(Method.java)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1563)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1451)

AppTheme No resource found

Error:(14, 24) No resource found that matches the given name (at 'theme' with value '@style/AppTheme').

gradle?

Thank you for your amazing lib! I'd like to use it but it has to be downloaded as a module. Can you host it on gradle please?

setRefreshing programmatically not working properly

Hi, I think you should add this couple of lines to your code as if you try to call setRefreshing(true) programmatically the drawable animation won't show.

public void setRefreshing(boolean refreshing) {
if (refreshing)
mRefreshDrawable.setPercent(1f);
if (mRefreshing != refreshing) {
setRefreshing(refreshing, false /* notify */);
}
}

Regards and thanks for your contribution.
Danny

java.lang.IndexOutOfBoundsException: Inconsistency detected. Invalid item position 3(offset:3).state:8

正在刷新时, 滑动recycleview, 报出这个异常 。
java.lang.IndexOutOfBoundsException: Inconsistency detected. Invalid item position 3(offset:3).state:8 at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:4659) at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:4617) at android.support.v7.widget.LinearLayoutManager$LayoutState.next(LinearLayoutManager.java:1994) at android.support.v7.widget.LinearLayoutManager.layoutChunk(LinearLayoutManager.java:1390) at android.support.v7.widget.LinearLayoutManager.fill(LinearLayoutManager.java:1353) at android.support.v7.widget.LinearLayoutManager.scrollBy(LinearLayoutManager.java:1180) at android.support.v7.widget.LinearLayoutManager.scrollVerticallyBy(LinearLayoutManager.java:1031) at android.support.v7.widget.RecyclerView.scrollByInternal(RecyclerView.java:1529) at android.support.v7.widget.RecyclerView.onTouchEvent(RecyclerView.java:2486) at android.view.View.dispatchTouchEvent(View.java:9306) at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2548) at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2241) at com.baoyz.widget.PullRefreshLayout.onTouchEvent(PullRefreshLayout.java:250) at android.view.View.dispatchTouchEvent(View.java:9306)

Improve Material Animation

Hi i like and use your libraries but I noticed that in the Material style the animation and the behavior is a little different than Google's one. If you can improve the animation it will be perfect! The differences are:

  1. now when refresh starts the view is created up the listview/scrollview and not above (like a surface)
  2. at the end the circle should scale and fade out instead of translate

like this http://material-design.storage.googleapis.com/publish/v_2/material_ext_publish/0B8v7jImPsDi-NllyUG1oSUx6XzA/070601_posSwipeYes_xdpi_v08b.webm

Thanks 😃

Scroll problem when having a ScrollView in the PullRefreshLayout

Hi,
I'm encountering a problem when I have a ScrollView inside your PullRefreshLayout.
When I scroll to the end of the ScrollView and I want to scroll back to the top,
the scroll is on PullRefreshLayout and not on the ScrollView.
So I can't scroll back when I go to the end of the ScrollView !

I'm not sure if it's very clear :/

RecyclerView with CardView-based items is not visible under PullRefreshLayout

Hi,

More details:

  1. general layout:

<com.baoyz.widget.PullRefreshLayout
    android:id="@+id/swipe_refresh_layout_plans"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <android.support.v7.widget.RecyclerView
        android:id="@+id/plan_list"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fillViewport="true" />

...

  1. item layout:

<android.support.v7.widget.CardView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginLeft="@dimen/keyline_left_medium_mini"
    android:layout_marginRight="@dimen/keyline_left_medium_mini"
    android:layout_marginTop="@dimen/keyline_left_medium_mini"
    android:elevation="@dimen/cardview_default_elevation"
    app:cardCornerRadius="@dimen/cardview_default_radius">

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

...

Once I move RecyclerView outside of PullRefreshLayout, it works as expected.

Customize drawable position..?

I have a recycler view having cardviews, now I want to have this drawable to come down from 3rd card and get the dragging effect from 3rd card onward..
Is it possible or can I have a snippet to make the modifications..??

D/Surface: Surface::setBuffersDimensions(this=0x7f98630600,w=800,h=1280)

There is so many many logs about "setBuffersDimensions" when already set refreshing(false).

//PullRefreshLayout.java
private Animation.AnimationListener mToStartListener = new Animation.AnimationListener() {
@OverRide
public void onAnimationStart(Animation animation) {
mRefreshDrawable.stop();
}

    @Override
    public void onAnimationRepeat(Animation animation) {
    }

    @Override
    public void onAnimationEnd(Animation animation) {

// mRefreshDrawable.stop();
mRefreshView.setVisibility(View.GONE);
mCurrentOffsetTop = mTarget.getTop();
}
};

After stop the mRefreshDrawable in onAnimationEnd(), the problem has been solved.

Obsolete

can this please get updated? it uses appcompat v21 and the latest version right now is v27. this library is incompatible and can not be used

Background issue

Hi, i want to change the color of the area that is behind the loading. But i have to do this without changing background of the list. Because, app has a unique background image which shown all pages and listview on it. How can i change only opened area color?
Thanks.

CanSwipeUp does not work

Currently wrapping a recycler view and the canChildScrollUp is always returning false so the list can no longer be scrolled upwards

PullRefreshLayout not available

<com.baoyz.widget.PullRefreshLayout
        android:id="@+id/swipeRefreshLayout"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
    <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical">
        <Button
                android:layout_width="match_parent"
                android:layout_height="wrap_content"/>
        <ListView
                android:id="@+id/listView"
                android:layout_width="match_parent"
                android:layout_height="match_parent"/>
    </LinearLayout>
</com.baoyz.widget.PullRefreshLayout>

get Notified when Pull is releasd

how can we get notified when pull is released without delay

since Onrefresh method in setonrefreshlister has Slight delay or how can we eliminate this delay

Refreshing in RecyclerView inside ViewPager

Hi, I got wrapped ViewPager by your pull refresh which inside generate RecyclerView

<pl.rlesniak.ptr.widget.PullRefreshLayout
       android:id="@+id/refresh_layout"
       android:layout_width="match_parent"
       android:layout_height="wrap_content">

              <android.support.v4.view.ViewPager
                  android:id="@+id/content_container"
                  android:layout_width="match_parent"
                  android:layout_height="wrap_content"/>

</pl.rlesniak.ptr.widget.PullRefreshLayout>

and I have a problem, when I scroll down everthing is fine, but when I want to get back the pull refresh is appearing. Do you have any solution? Except method mRecyclerView.setOnScrollListener()

How to import Android sudio

I import the project but not run this project .
my step:
step 1:
start android studio ---> import project--->select android-PullRefreshLayout-master folder
step 2:
android studio build

错误:FAILURE: Build failed with an exception.

  • What went wrong:
    Task '' not found in root project 'android-PullRefreshLayout-master'.
  • Try:
    Run gradle tasks to get a list of available tasks. Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

Animation Freeze while requesting server

refresh_layout.setOnRefreshListener(new PullRefreshLayout.OnRefreshListener() {

        @Override
        public void onRefresh() {
            // TODO Auto-generated method stub

            refresh_layout.post(new Runnable() {

                @Override
                public void run() {
                    // TODO Auto-generated method stub
                    refresh_layout.setRefreshing(true);
                                           // requesting to webservice
                }
            });
        }
    });

Pull up to refresh

I'm wondering how to pull up from bottom to refresh?
Is there any possible solution about this issue?

与CoordinatorLayout的冲突

你好,
当我把CoordinatorLayout、AppBarLayout、PullRefreshLayout{RecyclerView}联合使用时,
下拉刷新的优先级是高于CoordinatorLayout里的beHavior的,所以滑上去再滑下来后,会出现上面的AppBarLayout中的内容还没有显示完全,就出现下来刷新了。
如果有需要的画我可以提供gif哈

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.