44
55Android gesture refresh layout.
66
7- ## Installation
8- First, in your project's build.gradle add the jitpack.io repository like this:
9- ```
10- allprojects {
11- repositories {
12- ...
13- jcenter()
14- maven { url "https://jitpack.io" }
15- }
16- }
17- ```
18- * Note: do not add the jitpack.io repository under buildscript.*
19-
20-
21- Then, add the following dependency to your module's build.gradle file:
22- ```
23- dependencies {
24- ...
25- compile 'com.github.bvin:gesture-refresh-layout:0.1.1'
26- }
27- ```
28- If you want to get the latest feature, you can find that release the end with letter "d"(the code on
29- dev branch), example "com.github.bvin:gesture-refresh-layout:0.1.4d".The stable version is no end w
30- ith letter "d".
31-
32- If in your module already has support-v4 dependency, you should exclude the inner support module, li
33- ke this:
34- ```
35- compile ('com.github.bvin:gesture-refresh-layout:0.1.4d') {
36- exclude group: 'com.android.support', module: 'support-compat'
37- }
38- ```
7+ ## Swipe Gesture
8+ 1 . Both Translate, content and refresh view both translate, refresh view is next to content view transition.
9+ 2 . Content Translate, just translate content view.
10+ 3 . Refresher Translate, just translate refresh view.
11+ 4 . Both Fixed, content and refresh view both are fixed.
3912
4013## Usage
4114``` xml
@@ -57,14 +30,14 @@ mGestureRefreshLayout.setOnRefreshListener(new GestureRefreshLayout.OnRefreshLis
5730 // after close refresh.
5831 }
5932});
60- mGestureRefreshLayout. setOnGestureChangeListener(new GestureRefreshLayout .OnGestureStateChangeListener () {
61- @Override
62- public void onStartDrag (float startY ) {
63- mRefreshText. setText(" pull to refresh" );
64- }
33+ mGestureRefreshLayout. setOnGestureChangeListener(new GestureRefreshLayout .OnGestureStateChangeListener () {
34+ @Override
35+ public void onStartDrag (float startY ) {
36+ mRefreshText. setText(" pull to refresh" );
37+ }
6538
66- @Override
67- public void onDragging (float draggedDistance , float releaseDistance ) {
39+ @Override
40+ public void onDragging (float draggedDistance , float releaseDistance ) {
6841 // rotate angle: 360*draggedDistance/releaseDistance
6942 mProgressBar. setProgress((int ) (draggedDistance/ releaseDistance* 100 ));
7043 Log . d(TAG , " onDragging: " + draggedDistance+ " ," + releaseDistance);
@@ -74,13 +47,13 @@ mGestureRefreshLayout.setOnRefreshListener(new GestureRefreshLayout.OnRefreshLis
7447 mRefreshText. setText(" refreshing..." );
7548 }
7649
77- }
50+ }
7851
79- @Override
80- public void onFinishDrag (float endY ) {
81- mRefreshText. setText(" update..." );
82- }
83- });
52+ @Override
53+ public void onFinishDrag (float endY ) {
54+ mRefreshText. setText(" update..." );
55+ }
56+ });
8457
8558```
8659trigger refresh any where:
@@ -94,17 +67,50 @@ public boolean onOptionsItemSelected(MenuItem item) {
9467}
9568```
9669
97- ## Swipe Gesture
98- 1 . Both Translate, content and refresh view both translate, refresh view is next to content view transition.
99- 2 . Content Translate, just translate content view.
100- 3 . Refresher Translate, just translate refresh view.
101- 4 . Both Fixed, content and refresh view both are fixed.
70+ ## Installation
71+ First, in your project's build.gradle add the jitpack.io repository like this:
72+ ```
73+ allprojects {
74+ repositories {
75+ ...
76+ jcenter()
77+ maven { url "https://jitpack.io" }
78+ }
79+ }
80+ ```
81+ * Note: do not add the jitpack.io repository under buildscript.*
82+
83+
84+ Then, add the following dependency to your module's build.gradle file:
85+ ```
86+ dependencies {
87+ ...
88+ compile 'com.github.bvin:gesture-refresh-layout:0.1.7'
89+ }
90+ ```
91+ If you want to get the latest feature, you can find that release the end with letter "d"(the code on
92+ dev branch), example "com.github.bvin:gesture-refresh-layout:0.1.4d".The stable version is no end w
93+ ith letter "d".
94+
95+ If in your module already has support-v4 dependency, you should exclude the inner support module, li
96+ ke this:
97+ ```
98+ compile ('com.github.bvin:gesture-refresh-layout:0.1.4d') {
99+ exclude group: 'com.android.support', module: 'support-compat'
100+ }
101+ ```
102102
103103---
104104中文版
105105
106106Android手势刷新布局
107107
108+ ## 滑动手势
109+ 1 . 同步位移,即刷新视图跟随内容纵向位移,适合宽屏刷新视图。
110+ 2 . 悬浮位移,即内容视图固定,刷新视图跟着手势纵向位移,适合沉浸式刷新。
111+ 3 . 内容下潜位移,刷新视图固定,内容视图跟着手势纵向位移,这种情况一般是刷新视图会有吸引人的动画。
112+ 4 . 不位移,内容和刷新视图都不随手势位移,虽然纵向固定,但是可以通过其他形式来表现刷新行为。
113+
108114## 安装
109115首先,在项目根目录的build.gradle中添加JitPack远程仓库如下:
110116```
@@ -122,32 +128,22 @@ allprojects {
122128```
123129dependencies {
124130 ...
125- compile 'com.github.bvin:gesture-refresh-layout:0.1.1 '
131+ compile 'com.github.bvin:gesture-refresh-layout:0.1.7 '
126132}
127133```
128134如果需要最新的功能,可以依赖以d结尾的在dev分支上发布的Tag,如 "com.github.bvin:gesture-refresh-layout:0.
1291351.4d",稳定版是不以字母d结尾的。
130136
131137如果你的module中已经有support-v4依赖,应该去除内部的module,如下:
132138```
133- compile ('com.github.bvin:gesture-refresh-layout:0.1.4d ') {
139+ compile ('com.github.bvin:gesture-refresh-layout:0.1.7 ') {
134140 exclude group: 'com.android.support', module: 'support-compat'
135141 }
136142```
137143
138144## 用法
139145通常可以在GestureRefreshLayout布局里面添加子视图来实现刷新功能,第一个应为内容视图,第二个应为刷新视图。
140146
141- 原生SwipeRefreshLayout的ChildView的宽高会强制match_parent,而我们的GestureRefreshLayout可以支持Child
142- View为wrap_content。宽度不足match_parent的RefreshView将会处于水平居中位置,未来可提供gravity和margin
143- 的支持。
144-
145- 至于为何SRL(即SwipeRefreshLayout,以下通称SRL)会这样做,我猜测是因为SRL把触摸事件
146- 从ChildView拦截到SRL自身去做事件处理,它原生是可以从ChildView的区域滑出到SRL自身的区域,Touche事件可
147- 以无缝衔接,虽然...但是SRL和ChildView是没有间隙的,是严丝合缝的。而GRL(即GestureRefreshLayout,以下通
148- 称GRL)的ContentView是可以支持wrap_content的,就算你的ChildView小到比TouchSlop还小,依然可以在
149- ChildView外的GRL区域起作用。
150-
151147
152148``` xml
153149<GestureRefreshLayout >
@@ -186,6 +182,13 @@ public boolean onOptionsItemSelected(MenuItem item) {
186182 mGestureRefreshLayout. setEnabled(false );
187183```
188184
185+ GestureRefreshLayout默认是以RefreshView的高度作为释放刷新的距离(即当下拉出屏幕一个RefreshView的高度
186+ 就会触发刷新动作),如果你的RefreshView的高度小于默认高度或者大于3倍默认高度,将会以默认下拉高度作为
187+ 释放刷新距离,当然也可以完全自定义释放刷新的距离。
188+ ``` java
189+ mGestureRefreshLayout. setDistanceToTriggerSync(120 );
190+ ```
191+
189192####高级用法
190193GestureRefreshLayout的强大之处是可以非常个性化得定制刷新效果。通过GestureChange手势状态改变监听器可以
191194定制任何你想要的效果,OnGestureStateChangeListener接口有下列3个状态回掉。
@@ -221,17 +224,25 @@ mGestureRefreshLayout.setOnGestureChangeListener(new GestureRefreshLayout.OnGest
221224 }
222225});
223226```
227+ 自定义动画效果演示:
228+
229+ ![ 自定义动画效果演示] ( https://raw.githubusercontent.com/bvin/gesture-refresh-layout/dev/screen/gesture-refresh-advance.gif )
224230
225231_ 为了保持结构简洁、用法简单,GestureRefreshLayout只提供基础手势滑动动画,其他任何表现刷新的动画和提示
226232都需自己实现。_
227233
228- ## 滑动手势
229- 1 . 同步位移,即刷新视图跟随内容纵向位移,适合宽屏刷新视图。
230- 2 . 悬浮位移,即内容视图固定,刷新视图跟着手势纵向位移,适合沉浸式刷新。
231- 3 . 内容下潜位移,刷新视图固定,内容视图跟着手势纵向位移,这种情况一般是刷新视图会有吸引人的动画。
232- 4 . 不位移,内容和刷新视图都不随手势位移,虽然纵向固定,但是可以通过其他形式来表现刷新行为。
233234
234235## 实现原理
236+
237+ 原生SwipeRefreshLayout的ChildView的宽高会强制match_parent,而我们的GestureRefreshLayout可以支持Child
238+ View为wrap_content。宽度不足match_parent的RefreshView将会处于水平居中位置,未来可提供gravity和margin
239+ 的支持。
240+
241+ 至于为何SRL(即SwipeRefreshLayout,以下通称SRL)会这样做,我猜测是因为SRL把触摸事件
242+ 从ChildView拦截到SRL自身去做事件处理,它原生是可以从ChildView的区域滑出到SRL自身的区域,Touche事件可
243+ 以无缝衔接,虽然...但是SRL和ChildView是没有间隙的,是严丝合缝的。而GRL(即GestureRefreshLayout,以下通
244+ 称GRL)的ContentView是可以支持wrap_content的,就算你的ChildView小到比TouchSlop还小,依然可以在
245+ ChildView外的GRL区域起作用。
235246
236247 +--------------------+ ------> OriginOffsetTop
237248 | [ Refresh View] |
0 commit comments