Ultra Pull To Refresh - Deployment and Usage Guide
Prerequisites
- Android Studio (or any Android development environment)
- Android SDK with API Level 8 or higher
- Gradle build system (included with Android Studio)
- Java Development Kit (JDK) 8 or higher
Installation
Option 1: Add as Dependency (Recommended)
Add the following to your build.gradle file:
dependencies {
implementation 'in.srain.cube:ultra-ptr:1.0.11'
}
Option 2: Manual Integration
- Clone the repository:
git clone https://github.com/liaohuqiu/android-Ultra-Pull-To-Refresh.git
-
Import the
ptr-libmodule into your Android project -
Add the module as a dependency in your
settings.gradle:
include ':app', ':ptr-lib'
- In your app's
build.gradle, add:
dependencies {
implementation project(':ptr-lib')
}
Configuration
XML Configuration
Configure the PtrFrameLayout in your XML layout:
<in.srain.cube.views.ptr.PtrFrameLayout
android:id="@+id/store_house_ptr_frame"
xmlns:cube_ptr="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
cube_ptr:ptr_resistance="1.7"
cube_ptr:ptr_ratio_of_header_height_to_refresh="1.2"
cube_ptr:ptr_duration_to_close="300"
cube_ptr:ptr_duration_to_close_header="2000"
cube_ptr:ptr_keep_header_when_refresh="true"
cube_ptr:ptr_pull_to_fresh="false" >
<!-- Your content view here -->
</in.srain.cube.views.ptr.PtrFrameLayout>
Java Configuration
PtrFrameLayout mPtrFrame = findViewById(R.id.store_house_ptr_frame);
// Default settings
mPtrFrame.setResistance(1.7f);
mPtrFrame.setRatioOfHeaderHeightToRefresh(1.2f);
mPtrFrame.setDurationToClose(200);
mPtrFrame.setDurationToCloseHeader(1000);
mPtrFrame.setPullToRefresh(false);
Build & Run
Development
- Open the project in Android Studio
- Sync Gradle files
- Build and run on an emulator or physical device
Production
- Ensure your
build.gradlehas the correct version:
implementation 'in.srain.cube:ultra-ptr:1.0.11'
- Build the release APK:
./gradlew assembleRelease
- Sign the APK using your keystore
Deployment
Since this is an Android library, deployment involves:
-
Publishing to Maven Central (if you're the maintainer):
- Configure Sonatype OSSRH credentials
- Use Gradle Maven Publish plugin
- Run
./gradlew publish
-
Using in your app:
- Add the dependency to your app's
build.gradle - Sync and build
- Add the dependency to your app's
-
Testing:
- Use the provided demo APK: Download Demo APK
Troubleshooting
Common Issues and Solutions
1. Header not showing
- Ensure you've set a header view using
mPtrFrame.setHeaderView(headerView) - Check that the header view is properly sized and visible
2. Pull-to-refresh not working
- Verify you've called
mPtrFrame.setPullToRefresh(true)if you want pull-to-refresh behavior - Ensure the content view is scrollable (ListView, ScrollView, etc.)
3. Build errors with dependency
- Check your Gradle version compatibility
- Ensure you have internet access for downloading dependencies
- Try clearing the Gradle cache:
./gradlew clean
4. Runtime crashes
- Check that you're using API Level 8 or higher
- Verify all required views are properly initialized
- Look for null pointer exceptions in your header view implementation
5. Custom header not animating
- Implement the
PtrUIHandlerinterface in your custom header - Ensure you're calling the appropriate UI handler methods during refresh states
6. Performance issues
- Avoid complex layouts in the header view
- Use
ViewStubfor header content if it's heavy - Profile with Android Studio's profiler to identify bottlenecks
Additional Resources
- Demo APK: ptr-demo.apk
- GitHub Repository: https://github.com/liaohuqiu/android-Ultra-Pull-To-Refresh
- 中文版文档: README-cn.md
- Auto-load-more extension: https://github.com/liaohuqiu/android-cube-app