Skip to content

Commit de0692f

Browse files
committed
fix bugs on beta and update to v1.07.
1 parent 495fbfa commit de0692f

File tree

13 files changed

+351
-12
lines changed

13 files changed

+351
-12
lines changed

README.md

Lines changed: 109 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ TwinklingRefreshLayout extended the thoughts of SwipeRefreshLayout,using a ViewG
1010
- You can open a pure bounds rebound mode.
1111
- Lots of methods in the class OnRefreshListener.
1212
- It provides an interface to the callback during the sliding coefficient. Personalized offer good support.
13+
- NestedScroll,CoordinatorLayout
14+
15+
**Any View is supported.**
1316

1417
![](art/structure_v1.0.png)
1518

@@ -30,7 +33,7 @@ You can download these Videos for more details.
3033
## Usage
3134
#### 1.Add a gradle dependency.
3235
```
33-
compile 'com.lcodecorex:tkrefreshlayout:1.0.6'
36+
compile 'com.lcodecorex:tkrefreshlayout:1.0.7'
3437
```
3538

3639
#### 2.Add TwinklingRefreshLayout in the layout xml.
@@ -123,17 +126,26 @@ Make refresh-animation like SwipeRefreshLayout.
123126
##### setTargetView(View view)
124127
Set the target view that you can scroll.
125128

129+
##### setDefaultHeader、setDefaultFooter
130+
static methods aims to set a default header/footer in a/an Application/Activity.
131+
126132
#### 4.Attributes
127133
- tr_max_head_height - Flexible head height
128134
- tr_head_height - Head height
129135
- tr_max_bottom_height
130136
- tr_bottom_height - Bottom height
131137
- tr_overscroll_height - OverScroll Height
138+
- tr_enable_refresh - default is true
132139
- tr_enable_loadmore - default is true
133140
- tr_pureScrollMode_on - default is false
134141
- tr_overscroll_top_show - default is true
135142
- tr_overscroll_bottom_show - default is true
136143
- tr_enable_overscroll - default is true.
144+
- tr_floatRefresh - open the float-refresh mode.
145+
- tr_autoLoadMore
146+
- tr_enable_keepIView - default is true.
147+
- tr_showRefreshingWhenOverScroll - default is true.
148+
- tr_showLoadingWhenOverScroll - default is true.
137149

138150
## Other
139151
### 1.setOnRefreshListener
@@ -284,7 +296,103 @@ startAnim - be called automatically after the method onRefresh/onLoadMore is cal
284296

285297
Congratulations! Simple to use and simple to Personalise.(To see a more simple example. **TextHeaderView(pic 4)**)。
286298

299+
### NestedScroll
300+
#### TwinklingRefreshLayout Nested CoordinatorLayout
301+
---layout
302+
```xml
303+
<?xml version="1.0" encoding="utf-8"?>
304+
<com.lcodecore.tkrefreshlayout.TwinklingRefreshLayout xmlns:android="http://schemas.android.com/apk/res/android"
305+
xmlns:app="http://schemas.android.com/apk/res-auto"
306+
android:id="@+id/refresh"
307+
android:layout_width="match_parent"
308+
android:layout_height="match_parent">
309+
310+
<android.support.design.widget.CoordinatorLayout
311+
android:id="@+id/coord_container"
312+
android:layout_width="match_parent"
313+
android:layout_height="match_parent"
314+
android:addStatesFromChildren="true"
315+
android:fitsSystemWindows="true">
316+
317+
<android.support.design.widget.AppBarLayout
318+
android:id="@+id/appbar_layout"
319+
android:layout_width="match_parent"
320+
android:layout_height="wrap_content"
321+
android:clipChildren="false">
322+
323+
<!--...-->
324+
325+
</android.support.design.widget.AppBarLayout>
326+
327+
<android.support.v7.widget.RecyclerView
328+
android:id="@+id/recyclerview"
329+
android:layout_width="match_parent"
330+
android:layout_height="match_parent"
331+
app:layout_behavior="@string/appbar_scrolling_view_behavior" />
332+
333+
</android.support.design.widget.CoordinatorLayout>
334+
</com.lcodecore.tkrefreshlayout.TwinklingRefreshLayout>
335+
```
336+
337+
--- code1
338+
```
339+
refreshLayout.setTargetView(rv);
340+
```
341+
Find the RecyclerView/ListView.
342+
343+
--- code2
344+
```java
345+
AppBarLayout appBarLayout = (AppBarLayout) findViewById(R.id.appbar_layout);
346+
appBarLayout.addOnOffsetChangedListener(new AppBarLayout.OnOffsetChangedListener() {
347+
@Override
348+
public void onOffsetChanged(AppBarLayout appBarLayout, int verticalOffset) {
349+
if (verticalOffset >= 0) {
350+
refreshLayout.setEnableRefresh(true);
351+
refreshLayout.setEnableOverScroll(false);
352+
} else {
353+
refreshLayout.setEnableRefresh(false);
354+
refreshLayout.setEnableOverScroll(false);
355+
}
356+
}
357+
});
358+
```
359+
360+
####CoordinatorLayout nested TwinklingRefreshLayout
361+
--- layout
362+
```xml
363+
<?xml version="1.0" encoding="utf-8"?>
364+
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
365+
xmlns:app="http://schemas.android.com/apk/res-auto"
366+
android:id="@+id/coord_container"
367+
android:layout_width="match_parent"
368+
android:layout_height="match_parent"
369+
android:addStatesFromChildren="true"
370+
android:fitsSystemWindows="true">
371+
372+
<com.lcodecore.tkrefreshlayout.TwinklingRefreshLayout
373+
android:id="@+id/refresh"
374+
android:layout_width="match_parent"
375+
android:layout_height="match_parent"
376+
app:layout_behavior="@string/appbar_scrolling_view_behavior">
377+
378+
<android.support.v7.widget.RecyclerView
379+
android:id="@+id/recyclerview"
380+
android:layout_width="match_parent"
381+
android:layout_height="match_parent" />
382+
383+
</com.lcodecore.tkrefreshlayout.TwinklingRefreshLayout>
384+
385+
</android.support.design.widget.CoordinatorLayout>
386+
```
387+
Pay attention to `layout_behavior="@string/appbar_scrolling_view_behavior"` for TwinklingRefreshLayout.
388+
389+
287390
## Update Logs
391+
#### v1.07
392+
- NestedScroll,CoordinateLayout
393+
- Any View
394+
- Keep state when refreshing/loading.
395+
288396
#### v1.06
289397
- Repair memory leaks of customized Views.
290398
- remove the dependence of AVLoadingIndicatorView.

README_CN.md

Lines changed: 113 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ TwinklingRefreshLayout延伸了Google的SwipeRefreshLayout的思想,不在列表
77
4. 可开启没有刷新控件的纯净越界回弹模式
88
5. setOnRefreshListener中拥有大量可以回调的方法
99
6. 将Header和Footer抽象成了接口,并回调了滑动过程中的系数,方便实现个性化的Header和Footer
10+
7. 支持NestedScroll,嵌套CoordinatorLayout
11+
12+
**目前已经支持了所有的View,比如是一个FrameLayout,LinearLayout,AnyView。**
1013

1114
![](art/structure_v1.0.png)
1215

@@ -28,7 +31,7 @@ You can download these Videos for more details.
2831
#### 1.添加gradle依赖
2932
将libray模块复制到项目中,或者直接在build.gradle中依赖:
3033
```
31-
compile 'com.lcodecorex:tkrefreshlayout:1.0.6'
34+
compile 'com.lcodecorex:tkrefreshlayout:1.0.7'
3235
```
3336

3437
#### 2.在xml中添加TwinklingRefreshLayout
@@ -119,18 +122,31 @@ refreshLayout.setOnRefreshListener(new RefreshListenerAdapter(){
119122
##### setTargetView(View view)
120123
设置滚动事件的作用对象。
121124

125+
##### setDefaultHeader、setDefaultFooter
126+
现在已经提供了设置默认的Header、Footer的static方法,可在Application或者一个Activity中这样设置:
127+
```java
128+
TwinklingRefreshLayout.setDefaultHeader(SinaRefreshView.class.getName());
129+
TwinklingRefreshLayout.setDefaultFooter(BallPulseView.class.getName());
130+
```
131+
132+
122133
#### 4.扩展属性
123134
- tr_max_head_height 头部拉伸允许的最大高度
124135
- tr_head_height 头部高度
125136
- tr_max_bottom_height
126137
- tr_bottom_height 底部高度
127138
- tr_overscroll_height 允许越界的最大高度
139+
- tr_enable_refresh 是否允许刷新,默认为true
128140
- tr_enable_loadmore 是否允许加载更多,默认为true
129141
- tr_pureScrollMode_on 是否开启纯净的越界回弹模式
130142
- tr_overscroll_top_show - 否允许顶部越界时显示顶部View
131143
- tr_overscroll_bottom_show 是否允许底部越界时显示底部View
132144
- tr_enable_overscroll 是否允许越界回弹
133-
145+
- tr_floatRefresh 开启悬浮刷新模式
146+
- tr_autoLoadMore 越界时自动加载更多
147+
- tr_enable_keepIView 是否在开始刷新之后保持状态,默认为true;若需要保持原来的操作逻辑,这里设置为false即可
148+
- tr_showRefreshingWhenOverScroll 越界时直接显示正在刷新中的头部
149+
- tr_showLoadingWhenOverScroll 越界时直接显示正在加载更多中的底部
134150

135151
## 其它说明
136152
### 1.默认支持越界回弹,并可以随手势越界不同的高度
@@ -286,17 +302,110 @@ startAnim则是在onRefresh/onLoadMore之后才会回调的过程(此处是显
286302

287303
如上所示,轻而易举就可以实现一个个性化的Header或者Footer。(更简单的实现请参考Demo中的 **TextHeaderView(图四)**)。
288304

305+
### NestedScroll
306+
#### TwinklingRefreshLayout嵌套CoordinatorLayout
307+
---layout
308+
```xml
309+
<?xml version="1.0" encoding="utf-8"?>
310+
<com.lcodecore.tkrefreshlayout.TwinklingRefreshLayout xmlns:android="http://schemas.android.com/apk/res/android"
311+
xmlns:app="http://schemas.android.com/apk/res-auto"
312+
android:id="@+id/refresh"
313+
android:layout_width="match_parent"
314+
android:layout_height="match_parent">
315+
316+
<android.support.design.widget.CoordinatorLayout
317+
android:id="@+id/coord_container"
318+
android:layout_width="match_parent"
319+
android:layout_height="match_parent"
320+
android:addStatesFromChildren="true"
321+
android:fitsSystemWindows="true">
322+
323+
<android.support.design.widget.AppBarLayout
324+
android:id="@+id/appbar_layout"
325+
android:layout_width="match_parent"
326+
android:layout_height="wrap_content"
327+
android:clipChildren="false">
328+
329+
<!--...-->
330+
331+
</android.support.design.widget.AppBarLayout>
332+
333+
<android.support.v7.widget.RecyclerView
334+
android:id="@+id/recyclerview"
335+
android:layout_width="match_parent"
336+
android:layout_height="match_parent"
337+
app:layout_behavior="@string/appbar_scrolling_view_behavior" />
338+
339+
</android.support.design.widget.CoordinatorLayout>
340+
</com.lcodecore.tkrefreshlayout.TwinklingRefreshLayout>
341+
```
342+
343+
--- 代码1
344+
```
345+
refreshLayout.setTargetView(rv);
346+
```
347+
让refreshLayout能够找到RecyclerView/ListView
348+
349+
--- 代码2
350+
```java
351+
AppBarLayout appBarLayout = (AppBarLayout) findViewById(R.id.appbar_layout);
352+
appBarLayout.addOnOffsetChangedListener(new AppBarLayout.OnOffsetChangedListener() {
353+
@Override
354+
public void onOffsetChanged(AppBarLayout appBarLayout, int verticalOffset) {
355+
if (verticalOffset >= 0) {
356+
refreshLayout.setEnableRefresh(true);
357+
refreshLayout.setEnableOverScroll(false);
358+
} else {
359+
refreshLayout.setEnableRefresh(false);
360+
refreshLayout.setEnableOverScroll(false);
361+
}
362+
}
363+
});
364+
```
365+
设置AppBarLayout的移动监听器,需要下拉显示AppBarLayout时需设置setEnableRefresh(false),setEnableOverScroll(false);AppBarLayout隐藏后还原为原来设置的值即可。
366+
367+
####CoordinatorLayout嵌套TwinklingRefreshLayout
368+
--- layout
369+
```xml
370+
<?xml version="1.0" encoding="utf-8"?>
371+
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
372+
xmlns:app="http://schemas.android.com/apk/res-auto"
373+
android:id="@+id/coord_container"
374+
android:layout_width="match_parent"
375+
android:layout_height="match_parent"
376+
android:addStatesFromChildren="true"
377+
android:fitsSystemWindows="true">
378+
379+
<com.lcodecore.tkrefreshlayout.TwinklingRefreshLayout
380+
android:id="@+id/refresh"
381+
android:layout_width="match_parent"
382+
android:layout_height="match_parent"
383+
app:layout_behavior="@string/appbar_scrolling_view_behavior">
384+
385+
<android.support.v7.widget.RecyclerView
386+
android:id="@+id/recyclerview"
387+
android:layout_width="match_parent"
388+
android:layout_height="match_parent" />
389+
390+
</com.lcodecore.tkrefreshlayout.TwinklingRefreshLayout>
391+
392+
</android.support.design.widget.CoordinatorLayout>
393+
```
394+
注意给TwinklingRefreshLayout设置一个layout_behavior="@string/appbar_scrolling_view_behavior"
289395

290396
## TODO
291397
- 制作一个star相关的动效
292-
- CoordinateLayout及NestedScroll支持
293398
- 带视差效果的Header
294-
- 考虑是否需要控制底部下拉后或者顶部上拉后再次进入动画可以保持
295399

296400
## 更新日志
297401
#### v1.07
298402
- 你们要的设置默认刷新头/脚的方法来啦
299403
- Demo中集成StrictMode、BlockCanary检测ANR
404+
- 支持NestedScroll
405+
- 修复item点击失效/点击闪烁的问题
406+
- Nested滑动显示刷新头/尾支持
407+
- 支持刷新/加载更多状态保持
408+
- 空白View亦可刷新/加载
300409

301410
#### v1.06
302411
- 修复触摸监听失效问题

app/src/main/AndroidManifest.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
<activity android:name=".WebActivity"/>
2828
<activity android:name=".NestedLayoutActivity"/>
2929
<activity android:name=".CoordinateActivity"/>
30+
<activity android:name=".NormalViewActivity"/>
3031
<activity android:name=".TestActivity"/>
3132
</application>
3233

app/src/main/java/com/lcodecore/twinklingrefreshlayout/MainActivity.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ public void init() {
2323
findViewById(R.id.bt_enjoy).setOnClickListener(this);
2424
findViewById(R.id.bt_coordinate).setOnClickListener(this);
2525
findViewById(R.id.bt_test).setOnClickListener(this);
26+
findViewById(R.id.bt_normalView).setOnClickListener(this);
2627
}
2728

2829
@Override
@@ -49,6 +50,9 @@ public void onClick(View v) {
4950
case R.id.bt_coordinate:
5051
startActivity(new Intent(MainActivity.this,CoordinateActivity.class));
5152
break;
53+
case R.id.bt_normalView:
54+
startActivity(new Intent(MainActivity.this,NormalViewActivity.class));
55+
break;
5256
case R.id.bt_test:
5357
startActivity(new Intent(MainActivity.this,TestActivity.class));
5458
break;
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package com.lcodecore.twinklingrefreshlayout;
2+
3+
import android.os.Bundle;
4+
import android.support.v7.app.AppCompatActivity;
5+
6+
/**
7+
* Created by lcodecore on 2017/4/6.
8+
*/
9+
10+
public class NormalViewActivity extends AppCompatActivity {
11+
12+
@Override
13+
protected void onCreate(Bundle savedInstanceState) {
14+
super.onCreate(savedInstanceState);
15+
setContentView(R.layout.activity_normalview);
16+
}
17+
}

app/src/main/java/com/lcodecore/twinklingrefreshlayout/TestActivity.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public class TestActivity extends AppCompatActivity implements View.OnClickListe
2525
private TwinklingRefreshLayout refreshLayout;
2626

2727
private TestButton toggle_enableLoadmore, toggle_pureScrollMode_on, toggle_overScrollTopShow, toggle_osFooterShow, toggle_enableOverScroll, toggle_enableKeepIView,
28-
toggle_showRefreshingWhenOverScroll, toggle_showLoadingWhenOverScroll, toggle_floatRefresh, toggle_autoLoadMore;
28+
toggle_showRefreshingWhenOverScroll, toggle_showLoadingWhenOverScroll, toggle_floatRefresh, toggle_autoLoadMore,toggle_enableRefresh;
2929

3030
@Override
3131
protected void onCreate(Bundle savedInstanceState) {
@@ -50,6 +50,7 @@ public void onClick(View v) {
5050
toggle_showLoadingWhenOverScroll = new TestButton(R.id.toggle_showLoadingWhenOverScroll, "showLoadingWhenOS", true);
5151
toggle_floatRefresh = new TestButton(R.id.toggle_floatRefresh, "floatRefresh", false);
5252
toggle_autoLoadMore = new TestButton(R.id.toggle_autoLoadMore, "autoLoadMore", false);
53+
toggle_enableRefresh = new TestButton(R.id.toggle_enableRefresh,"enableRefresh",true);
5354
}
5455

5556
private void setupGridView(GridView gridView) {
@@ -142,6 +143,9 @@ public void onClick(View v) {
142143
toggle_autoLoadMore.toggle();
143144
refreshLayout.setAutoLoadMore(toggle_autoLoadMore.flag);
144145
break;
146+
case R.id.toggle_enableRefresh:
147+
toggle_enableRefresh.toggle();
148+
refreshLayout.setEnableRefresh(toggle_enableRefresh.flag);
145149
}
146150
}
147151

0 commit comments

Comments
 (0)