Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
A

android-Ultra-Pull-To-Refresh

> 编程语言
Open source

Ultra Pull to Refresh for Android. Support all the views.

9.5K stars0 likes2 views
WebsiteGitHub

About

Ultra Pull to Refresh for Android. Support all the views.

Welcome to follow me on GitHub or Twitter

GitHub: https://github.com/liaohuqiu

Twitter: https://twitter.com/liaohuqiu


中文版文档

Wanna auto-load-more? This will be what you want: https://github.com/liaohuqiu/android-cube-app

Ultra Pull To Refresh

It's a replacement for the deprecated pull to refresh solution. It can contain any view you want.

It's easy to use and more powerful than SwipeRefreshLayout.

It's well designed, you can customize the UI effect you want as easy as adding a headview to ListView.

Support API LEVEL >= 8, all snapshots are taken from Genymotion, 2.3.7.

Download APK

  • StoreHouse Style first! Thanks to CBStoreHouseRefreshControl.

  • Material Style, added @ 2014-12-09. There is a beautiful shadow which looks terrible in gif snapshot. Please Check out the DEMO.

  • Supports all of the views: ListView, GridView, ScrollView, FrameLayout, or Even a single TextView.

  • Supports all of the refresh types.

    • pull to refresh

    • release to refresh

    • keep header when refresh

    • hide header when refresh

    • auto refresh

Usage

Maven Central

This project has been pushed to Maven Central, both in aar and apklib.

The latest version: 1.0.11, has been published to: https://oss.sonatype.org/content/repositories/snapshots, in gradle:

maven {
    url 'https://oss.sonatype.org/content/repositories/snapshots'
}

The stable version: 1.0.11, https://oss.sonatype.org/content/repositories/releases, in gradle:

mavenCentral()

pom.xml, latest version:

xml
<dependency>
    <groupId>in.srain.cube</groupId>
    <artifactId>ultra-ptr</artifactId>
    <type>aar</type>
    
    
    <version>1.0.11</version>
</dependency>

pom.xml, stable version:

xml
<dependency>
    <groupId>in.srain.cube</groupId>
    <artifactId>ultra-ptr</artifactId>
    <type>aar</type>
    
    
    <version>1.0.11</version>
</dependency>

gradle, latest version:

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

gradle, stable version:

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

Config

There are 6 properties:

  • Resistence

    This is the resistence while you are moving the frame, default is: 1.7f.

  • Ratio of the Height of the Header to Refresh

    The ratio of the height of the header to trigger refresh, default is: 1.2f.

  • Duration to Close

    The duration for moving from the position you relase the view to the height of header, default is 200ms.

  • Duration to Close Header

    The default value is 1000ms

  • Keep Header while Refreshing

    The default value is true.

  • Pull to Refresh / Release to Refresh

    The default value is Release to Refresh.

Config in xml
…

Or config in java code

java
// the following are default settings
mPtrFrame.setResistance(1.7f);
mPtrFrame.setRatioOfHeaderHeightToRefresh(1.2f);
mPtrFrame.setDurationToClose(200);
mPtrFrame.setDurationToCloseHeader(1000);
// default is false
mPtrFrame.setPullToRefresh(false);
// default is true
mPtrFrame.setKeepHeaderWhenRefresh(true);

Other Config

  • setPinContent. Pin the content, only the HeaderView will be moved.

    This's the the performance of material style in support package v19.

StoreHouse Style

  • Config using string:
java
// header
final StoreHouseHeader header = new StoreHouseHeader(getContext());
header.setPadding(0, LocalDisplay.dp2px(15), 0, 0);

/**
 * using a string, support: A-Z 0-9 - .
 * you can add more letters by {@link in.srain.cube.views.ptr.header.StoreHousePath#addChar}
 */
header.initWithString('Alibaba');
  • Config using string array from xml:
java
header.initWithStringArray(R.array.storehouse);

And in res/values/arrays.xml:

xml
<resources>
    <string-array name="storehouse">
        <item>0,35,12,42,</item>
        <item>12,42,24,35,</item>
        <item>24,35,12,28,</item>
        <item>0,35,12,28,</item>
        <item>0,21,12,28,</item>
        <item>12,28,24,21,</item>
        <item>24,35,24,21,</item>
        <item>24,21,12,14,</item>
        <item>0,21,12,14,</item>
        <item>0,21,0,7,</item>
        <item>12,14,0,7,</item>
        <item>12,14,24,7,</item>
        <item>24,7,12,0,</item>
        <item>0,7,12,0,</item>
    </string-array>
</resources>

Process Refresh

There is a PtrHandler, by which you can refresh the data.

public interface PtrHandler {

    /**
     * Check can do refresh or not. For example the content is empty or the first child is in view.
     * <p/>
     * {@link in.srain.cube.views.ptr.PtrDefaultHandler#checkContentCanBePulledDown}
     */
    public boolean checkCanDoRefresh(final PtrFrameLayout frame, final View content, final View header);

    /**
     * When refresh begin
     *
     * @param frame
     */
    public void onRefreshBegin(final PtrFrameLayout frame);
}

An example:

java
ptrFrame.setPtrHandler(new PtrHandler() {
    @Override
    public void onRefreshBegin(PtrFrameLayout frame) {
        frame.postDelayed(new Runnable() {
            @Override
            public void run() {
                ptrFrame.refreshComplete();
            }
        }, 1800);
    }

    @Override
    public boolean checkCanDoRefresh(PtrFrameLayout frame, View content, View header) {
        return PtrDefaultHandler.checkContentCanBePulledDown(frame, content, header);
    }
});

Customize

You can add a PtrUIHandler to PtrFrameLayout to implement any UI effect you want.

…

Q & A

  • work with ViewPager: disableWhenHorizontalMove()

  • work with LongPressed, setInterceptEventWhileWorking()

Contact & Help

Please fell free to contact me if there is any problem when using the library.

  • [email protected]

  • twitter: https://twitter.com/liaohuqiu

  • weibo: http://weibo.com/liaohuqiu

  • blog: http://www.liaohuqiu.net

    1. About how to use cube-sdk / Ultra Ptr: 271918140 (cube-sdk)

      This the rule for our tribes, please read it before you request to join: https://github.com/liaohuqiu/qq-tribe-rule

    2. For those who like thinking independently and are good at solving problem independently. Please join us, we are all here on Slack:

      http://join-add1bit.liaohuqiu.net/

Issues· 174 open

View all issuesOpen on GitHub
  • #352

    You're on the SigRank board — claim your profile or remove it

    Updated Jul 14, 2026
  • #327

    coordinatorlayout 嵌套 android-Ultra-Pull-To-Refresh 下拉刷新不灵敏

    Updated Mar 21, 2024
  • #345

    闪退啊

    Updated Dec 15, 2020
  • #275

    如何让下拉的距离固定?

    Updated May 22, 2020
  • #342

    嵌套WebView的问题,WebView网页中使用了滑动控件,滑动webView 然后下拉webView 不能滑动到顶部,直接下拉刷新了,请问怎么解决?

    Updated Dec 27, 2019
  • #309

    IndexOutOfBoundsException Inconsistency detected

    Updated Oct 24, 2019
  • #344

    PtrClassicFrameLayout 嵌套RelativeLayout头部被裁减了

    Updated Sep 9, 2019
  • #326

    能不能实现模仿朋友圈下拉刷新

    Updated May 9, 2019
  • #335

    能不能设置禁止下拉刷新

    Updated Apr 30, 2019
  • #119

    disable pull to refresh when item clicking or touching?

    Updated Mar 14, 2019

> Tags

Java

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 29, 2026
Category编程语言
PricingOpen source

> Related tools

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言