Skip to content

Commit d359895

Browse files
committed
添加常见问题
1 parent 1c25092 commit d359895

File tree

13 files changed

+306
-150
lines changed

13 files changed

+306
-150
lines changed

README.md

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
[![License](https://img.shields.io/badge/License%20-Apache%202-337ab7.svg)](https://www.apache.org/licenses/LICENSE-2.0)
44
[![Arsenal](https://img.shields.io/badge/Arsenal%20-%20SmartRefresh-4cae4c.svg)](https://android-arsenal.com/details/1/6001)
5-
[![JCenter](https://img.shields.io/badge/%20JCenter%20-1.1.0-5bc0de.svg)](https://bintray.com/scwang90/maven/SmartRefreshLayout/_latestVersion)
5+
[![JCenter](https://img.shields.io/badge/%20JCenter%20-2.0.0-5bc0de.svg)](https://bintray.com/scwang90/maven/refresh-layout-kernel/_latestVersion)
66
[![MinSdk](https://img.shields.io/badge/%20MinSdk%20-%2012%2B%20-f0ad4e.svg)](https://android-arsenal.com/api?level=12)
77
[![Methods](https://img.shields.io/badge/Methods%20%7C%20Size%20-%20784%20%7C%20121%20KB-d9534f.svg)](http://www.methodscount.com/?lib=com.scwang.smartrefresh%3ASmartRefreshLayout%3A1.0.4)
88

@@ -129,6 +129,8 @@ V2.x 版本已经把依赖库拆分成8个包啦,用到的时候自行引用
129129
## 简单用例
130130
#### 1.在 build.gradle 中添加依赖
131131

132+
[【V1.1.0】](https://github.com/scwang90/SmartRefreshLayout/tree/1.x#%E7%AE%80%E5%8D%95%E7%94%A8%E4%BE%8B) 如果正在使用1.x 版本请调转,当前2.0 版本已经重定制,不支持升级,请在新项目中使用。
133+
132134
V2.x 相对于 V1.x 对包名做了修改如:com.scwang.smartrefresh 改为 com.scwang.smart.refresh。
133135
建议在新项目中使用,如果项目升级,java,xml 中都需要做包名替换,比较麻烦。
134136
但主要改动还是对 Smart 进行分包,减小不必要的依赖,比如不使用二级刷新就不依赖,避免代码冗余。
@@ -137,21 +139,21 @@ V2.x 相对于 V1.x 对包名做了修改如:com.scwang.smartrefresh 改为 co
137139

138140
```
139141
// 注意:分包之后不会有默认的Header和Footer需要手动添加!还是原来的三种方法!
140-
implementation 'com.scwang.smart:refresh-layout-kernel:2.0.0-alpha-1' //核心必须依赖
141-
implementation 'com.scwang.smart:refresh-header-classics:2.0.0-alpha-1' //经典刷新头
142-
implementation 'com.scwang.smart:refresh-header-radar:2.0.0-alpha-1' //雷达刷新头
143-
implementation 'com.scwang.smart:refresh-header-falsify:2.0.0-alpha-1' //虚拟刷新头
144-
implementation 'com.scwang.smart:refresh-header-material:2.0.0-alpha-1' //谷歌刷新头
145-
implementation 'com.scwang.smart:refresh-header-two-level:2.0.0-alpha-1' //二级刷新头
146-
implementation 'com.scwang.smart:refresh-footer-ball:2.0.0-alpha-1' //球脉冲加载
147-
implementation 'com.scwang.smart:refresh-footer-classics:2.0.0-alpha-1' //经典加载
142+
implementation 'com.scwang.smart:refresh-layout-kernel:2.0.0' //核心必须依赖
143+
implementation 'com.scwang.smart:refresh-header-classics:2.0.0' //经典刷新头
144+
implementation 'com.scwang.smart:refresh-header-radar:2.0.0' //雷达刷新头
145+
implementation 'com.scwang.smart:refresh-header-falsify:2.0.0' //虚拟刷新头
146+
implementation 'com.scwang.smart:refresh-header-material:2.0.0' //谷歌刷新头
147+
implementation 'com.scwang.smart:refresh-header-two-level:2.0.0' //二级刷新头
148+
implementation 'com.scwang.smart:refresh-footer-ball:2.0.0' //球脉冲加载
149+
implementation 'com.scwang.smart:refresh-footer-classics:2.0.0' //经典加载
148150
149151
```
150152

151153
<!-- // 保留了 com.scwang.smartrefresh 的包名,但不分包 -->
152-
<!-- implementation 'com.scwang.smartrefresh:SmartRefreshHeader:2.0.0-alpha-1' //各种Header集合 -->
153-
<!-- implementation 'com.scwang.smartrefresh:SmartRefreshFooter:2.0.0-alpha-1' //各种Footer集合 -->
154-
<!-- implementation 'com.scwang.smartrefresh:SmartRefreshLayout:2.0.0-alpha-1' //核心、默认Header、默认Footer -->
154+
<!-- implementation 'com.scwang.smartrefresh:SmartRefreshHeader:2.0.0' //各种Header集合 -->
155+
<!-- implementation 'com.scwang.smartrefresh:SmartRefreshFooter:2.0.0' //各种Footer集合 -->
156+
<!-- implementation 'com.scwang.smartrefresh:SmartRefreshLayout:2.0.0' //核心、默认Header、默认Footer -->
155157

156158
如果使用 AndroidX 在 gradle.properties 中添加
157159

README_EN.md

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
[![License](https://img.shields.io/badge/License%20-Apache%202-337ab7.svg)](https://www.apache.org/licenses/LICENSE-2.0)
44
[![Arsenal](https://img.shields.io/badge/Arsenal%20-%20SmartRefresh-4cae4c.svg)](https://android-arsenal.com/details/1/6001)
5-
[![JCenter](https://img.shields.io/badge/%20Jcenter%20-1.1.0-5bc0de.svg)](https://bintray.com/scwang90/maven/SmartRefreshLayout/_latestVersion)
5+
[![JCenter](https://img.shields.io/badge/%20Jcenter%20-2.0.0-5bc0de.svg)](https://bintray.com/scwang90/maven/refresh-layout-kernel/_latestVersion)
66
[![MinSdk](https://img.shields.io/badge/%20MinSdk%20-%2012%2B%20-f0ad4e.svg)](https://android-arsenal.com/api?level=12)
77
[![Methods](https://img.shields.io/badge/Methods%20%7C%20Size%20-%20784%20%7C%20122%20KB-d9534f.svg)](http://www.methodscount.com/?lib=com.scwang.smartrefresh%3ASmartRefreshLayout%3A1.1.0)
88

@@ -114,20 +114,20 @@ It is recommended that you copy the source code into the project whenever you ne
114114

115115
```
116116
// Note: There will be no default Header and Footer after subcontracting. It needs to be added manually!
117-
implementation 'com.scwang.smart:refresh-layout-kernel:2.0.0-alpha-1' //core
118-
implementation 'com.scwang.smart:refresh-header-classics:2.0.0-alpha-1' //ClassicsHeader
119-
implementation 'com.scwang.smart:refresh-header-radar:2.0.0-alpha-1' //BezierRadarHeader
120-
implementation 'com.scwang.smart:refresh-header-falsify:2.0.0-alpha-1' //FalsifyHeader
121-
implementation 'com.scwang.smart:refresh-header-material:2.0.0-alpha-1' //MaterialHeader
122-
implementation 'com.scwang.smart:refresh-header-two-level:2.0.0-alpha-1' //TwoLevelHeader
123-
implementation 'com.scwang.smart:refresh-footer-ball:2.0.0-alpha-1' //BallPulseFooter
124-
implementation 'com.scwang.smart:refresh-footer-classics:2.0.0-alpha-1' //ClassicsFooter
117+
implementation 'com.scwang.smart:refresh-layout-kernel:2.0.0' //core
118+
implementation 'com.scwang.smart:refresh-header-classics:2.0.0' //ClassicsHeader
119+
implementation 'com.scwang.smart:refresh-header-radar:2.0.0' //BezierRadarHeader
120+
implementation 'com.scwang.smart:refresh-header-falsify:2.0.0' //FalsifyHeader
121+
implementation 'com.scwang.smart:refresh-header-material:2.0.0' //MaterialHeader
122+
implementation 'com.scwang.smart:refresh-header-two-level:2.0.0' //TwoLevelHeader
123+
implementation 'com.scwang.smart:refresh-footer-ball:2.0.0' //BallPulseFooter
124+
implementation 'com.scwang.smart:refresh-footer-classics:2.0.0' //ClassicsFooter
125125
126126
```
127127
<!-- // The package name of `com.scwang.smartrefresh` is retained, but not subcontracted. -->
128-
<!-- implementation 'com.scwang.smartrefresh:SmartRefreshHeader:2.0.0-alpha-1' //Headers -->
129-
<!-- implementation 'com.scwang.smartrefresh:SmartRefreshFooter:2.0.0-alpha-1' //Footers -->
130-
<!-- implementation 'com.scwang.smartrefresh:SmartRefreshLayout:2.0.0-alpha-1' //core、 default Header and Footer -->
128+
<!-- implementation 'com.scwang.smartrefresh:SmartRefreshHeader:2.0.0' //Headers -->
129+
<!-- implementation 'com.scwang.smartrefresh:SmartRefreshFooter:2.0.0' //Footers -->
130+
<!-- implementation 'com.scwang.smartrefresh:SmartRefreshLayout:2.0.0' //core、 default Header and Footer -->
131131

132132
If you use AndroidX, add it to gradle.properties
133133

app/build.gradle

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,18 @@ dependencies {
6363
releaseImplementation 'com.squareup.leakcanary:leakcanary-android-no-op:1.6.3'
6464
testImplementation 'com.squareup.leakcanary:leakcanary-android-no-op:1.6.3'
6565

66-
// implementation project(':refresh-footer')
66+
implementation project(':refresh-footer')
6767
implementation project(':refresh-header')
6868
implementation project(':refresh-layout')
69+
implementation project(':refresh-drawable-path')
70+
71+
implementation project(':refresh-layout-kernel')
72+
implementation project(':refresh-header-classics')
73+
implementation project(':refresh-header-radar')
74+
implementation project(':refresh-header-falsify')
75+
implementation project(':refresh-header-material')
76+
implementation project(':refresh-header-two-level')
77+
implementation project(':refresh-footer-ball')
6978

7079
// implementation 'com.scwang.smart:refresh-layout-kernel:2.0.0-alpha-1' //核心必须依赖
7180
// implementation 'com.scwang.smart:refresh-header-classics:2.0.0-alpha-1' //经典刷新头

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,5 @@ org.gradle.jvmargs=-Xmx1536m
1818

1919
SMART_USER=scwang90
2020
SMART_GROUP=com.scwang.smart
21-
SMART_VERSION=2.0.0-alpha-1
21+
SMART_VERSION=2.0.0
2222
SMART_PUBLISH=false

refresh-footer-classics/src/main/java/com/scwang/smart/refresh/footer/ClassicsFooter.java

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -170,18 +170,24 @@ public ClassicsFooter(Context context, AttributeSet attrs) {
170170
//</editor-fold>
171171

172172
//<editor-fold desc="RefreshFooter">
173-
@Override
174-
public void onStartAnimator(@NonNull RefreshLayout refreshLayout, int height, int maxDragHeight) {
175-
if (!mNoMoreData) {
176-
super.onStartAnimator(refreshLayout, height, maxDragHeight);
177-
}
178-
}
173+
// @Override
174+
// public void onStartAnimator(@NonNull RefreshLayout refreshLayout, int height, int maxDragHeight) {
175+
// if (!mNoMoreData) {
176+
// super.onStartAnimator(refreshLayout, height, maxDragHeight);
177+
// }
178+
// }
179179

180180
@Override
181181
public int onFinish(@NonNull RefreshLayout layout, boolean success) {
182+
/*
183+
* 2020-5-15 修复BUG
184+
* https://github.com/scwang90/SmartRefreshLayout/issues/1003
185+
* 修复 没有更多数据之后 loading 还在显示问题
186+
*/
187+
super.onFinish(layout, success);
182188
if (!mNoMoreData) {
183189
mTitleText.setText(success ? mTextFinish : mTextFailed);
184-
return super.onFinish(layout, success);
190+
return mFinishDuration;
185191
}
186192
return 0;
187193
}

refresh-footer/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ dependencies {
3232
})
3333
testImplementation 'junit:junit:4.12'
3434

35-
api project(':refresh-footer-ball')
36-
api project(':refresh-footer-classics')
35+
compileOnly project(':refresh-footer-ball')
36+
compileOnly project(':refresh-footer-classics')
3737
compileOnly project(':refresh-layout')
3838
}
3939

refresh-header-falsify/src/main/java/com/scwang/smart/refresh/header/FalsifyFooter.java

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
import com.scwang.smart.refresh.layout.api.RefreshFooter;
99
import com.scwang.smart.refresh.layout.api.RefreshKernel;
1010
import com.scwang.smart.refresh.layout.api.RefreshLayout;
11-
import com.scwang.smart.refresh.layout.constant.RefreshState;
1211

1312
/**
1413
* 虚假的 Footer
@@ -38,11 +37,18 @@ public void onInitialized(@NonNull RefreshKernel kernel, int height, int maxDrag
3837
@Override
3938
public void onReleased(@NonNull RefreshLayout layout, int height, int maxDragHeight) {
4039
if (mRefreshKernel != null) {
41-
mRefreshKernel.setState(RefreshState.None);
42-
//onReleased 的时候 调用 setState(RefreshState.None); 并不会立刻改变成 None
43-
//而是先执行一个回弹动画,LoadFinish 是介于 Refreshing 和 None 之间的状态
44-
//LoadFinish 用于在回弹动画结束时候能顺利改变为 None
45-
mRefreshKernel.setState(RefreshState.LoadFinish);
40+
/*
41+
* 2020-3-15 BUG修复
42+
* https://github.com/scwang90/SmartRefreshLayout/issues/1018
43+
* 强化了 closeHeaderOrFooter 的关闭逻辑,帮助 Footer 取消刷新
44+
* FalsifyFooter 是不能触发加载的
45+
*/
46+
layout.closeHeaderOrFooter();
47+
// mRefreshKernel.setState(RefreshState.None);
48+
// //onReleased 的时候 调用 setState(RefreshState.None); 并不会立刻改变成 None
49+
// //而是先执行一个回弹动画,LoadFinish 是介于 Refreshing 和 None 之间的状态
50+
// //LoadFinish 用于在回弹动画结束时候能顺利改变为 None
51+
// mRefreshKernel.setState(RefreshState.LoadFinish);
4652
}
4753
}
4854
//</editor-fold>

refresh-header-falsify/src/main/java/com/scwang/smart/refresh/header/FalsifyHeader.java

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
import com.scwang.smart.refresh.header.falsify.FalsifyAbstract;
88
import com.scwang.smart.refresh.layout.api.RefreshHeader;
99
import com.scwang.smart.refresh.layout.api.RefreshLayout;
10-
import com.scwang.smart.refresh.layout.constant.RefreshState;
1110

1211
/**
1312
* 虚假的 Header
@@ -32,11 +31,18 @@ public FalsifyHeader(Context context, AttributeSet attrs) {
3231
@Override
3332
public void onReleased(@NonNull RefreshLayout layout, int height, int maxDragHeight) {
3433
if (mRefreshKernel != null) {
35-
mRefreshKernel.setState(RefreshState.None);
36-
//onReleased 的时候 调用 setState(RefreshState.None); 并不会立刻改变成 None
37-
//而是先执行一个回弹动画,RefreshFinish 是介于 Refreshing 和 None 之间的状态
38-
//RefreshFinish 用于在回弹动画结束时候能顺利改变为 None
39-
mRefreshKernel.setState(RefreshState.RefreshFinish);
34+
/*
35+
* 2020-3-15 BUG修复
36+
* https://github.com/scwang90/SmartRefreshLayout/issues/1018
37+
* 强化了 closeHeaderOrFooter 的关闭逻辑,帮助 Header 取消刷新
38+
* FalsifyHeader 是不能触发刷新的
39+
*/
40+
layout.closeHeaderOrFooter();
41+
// mRefreshKernel.setState(RefreshState.None);
42+
// //onReleased 的时候 调用 setState(RefreshState.None); 并不会立刻改变成 None
43+
// //而是先执行一个回弹动画,RefreshFinish 是介于 Refreshing 和 None 之间的状态
44+
// //RefreshFinish 用于在回弹动画结束时候能顺利改变为 None
45+
// mRefreshKernel.setState(RefreshState.RefreshFinish);
4046
}
4147
}
4248
//</editor-fold>

refresh-header-two-level/src/main/java/com/scwang/smart/refresh/header/TwoLevelHeader.java

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ public class TwoLevelHeader extends SimpleComponent implements RefreshHeader, Ne
3636
protected float mMaxRate = 2.5f;
3737
protected float mFloorRate = 1.9f;
3838
protected float mRefreshRate = 1f;
39+
protected boolean mEnableRefresh = true;
3940
protected boolean mEnableTwoLevel = true;
4041
protected boolean mEnablePullToCloseTwoLevel = true;
4142
protected int mFloorDuration = 1000;
@@ -62,6 +63,7 @@ public TwoLevelHeader(Context context, @Nullable AttributeSet attrs) {
6263
mFloorRate = ta.getFloat(R.styleable.TwoLevelHeader_srlFloorRate, mFloorRate);
6364
mRefreshRate = ta.getFloat(R.styleable.TwoLevelHeader_srlRefreshRate, mRefreshRate);
6465
mFloorDuration = ta.getInt(R.styleable.TwoLevelHeader_srlFloorDuration, mFloorDuration);
66+
mEnableRefresh = ta.getBoolean(R.styleable.TwoLevelHeader_srlEnableRefresh, mEnableRefresh);
6567
mEnableTwoLevel = ta.getBoolean(R.styleable.TwoLevelHeader_srlEnableTwoLevel, mEnableTwoLevel);
6668
mEnablePullToCloseTwoLevel = ta.getBoolean(R.styleable.TwoLevelHeader_srlEnablePullToCloseTwoLevel, mEnablePullToCloseTwoLevel);
6769

@@ -162,6 +164,9 @@ public void onStateChanged(@NonNull RefreshLayout refreshLayout, @NonNull Refres
162164
final RefreshComponent refreshHeader = mRefreshHeader;
163165
if (refreshHeader != null) {
164166
final OnStateChangedListener listener = mRefreshHeader;
167+
if (newState == RefreshState.ReleaseToRefresh && !mEnableRefresh) {
168+
newState = RefreshState.PullDownToRefresh;
169+
}
165170
listener.onStateChanged(refreshLayout, oldState, newState);
166171
switch (newState) {
167172
case TwoLevelReleased:
@@ -203,8 +208,10 @@ public void onMoving(boolean isDragging, float percent, int offset, int height,
203208
refreshKernel.setState(RefreshState.ReleaseToTwoLevel);
204209
} else if (mPercent >= mFloorRate && percent < mRefreshRate) {
205210
refreshKernel.setState(RefreshState.PullDownToRefresh);
206-
} else if (mPercent >= mFloorRate && percent < mFloorRate) {
211+
} else if (mPercent >= mFloorRate && percent < mFloorRate && mEnableRefresh) {
207212
refreshKernel.setState(RefreshState.ReleaseToRefresh);
213+
} else if (!mEnableRefresh && refreshKernel.getRefreshLayout().getState() != RefreshState.ReleaseToTwoLevel) {
214+
refreshKernel.setState(RefreshState.PullDownToRefresh);
208215
}
209216
mPercent = percent;
210217
}
@@ -275,7 +282,7 @@ public void onNestedPreScroll(@NonNull View target, int dx, int dy, @NonNull int
275282
* @return TwoLevelHeader
276283
*/
277284
public TwoLevelHeader setRefreshHeader(RefreshHeader header) {
278-
return setRefreshHeader(header, MATCH_PARENT, WRAP_CONTENT);
285+
return setRefreshHeader(header, 0, 0);
279286
}
280287

281288
/**
@@ -288,15 +295,26 @@ public TwoLevelHeader setRefreshHeader(RefreshHeader header) {
288295
public TwoLevelHeader setRefreshHeader(RefreshHeader header, int width, int height) {
289296
final ViewGroup thisGroup = this;
290297
if (header != null) {
298+
/*
299+
* 2020-3-16 修复 header 中自带 LayoutParams 丢失问题
300+
*/
301+
width = width == 0 ? MATCH_PARENT : width;
302+
height = height == 0 ? WRAP_CONTENT : height;
303+
LayoutParams lp = new LayoutParams(width, height);
304+
Object olp = header.getView().getLayoutParams();
305+
if (olp instanceof LayoutParams) {
306+
lp = ((LayoutParams) olp);
307+
}
308+
291309
RefreshComponent refreshHeader = mRefreshHeader;
292310
if (refreshHeader != null) {
293311
thisGroup.removeView(refreshHeader.getView());
294312
}
295313
refreshHeader = header;
296314
if (refreshHeader.getSpinnerStyle() == SpinnerStyle.FixedBehind) {
297-
thisGroup.addView(refreshHeader.getView(), 0, new LayoutParams(width, height));
315+
thisGroup.addView(refreshHeader.getView(), 0, lp);
298316
} else {
299-
thisGroup.addView(refreshHeader.getView(), thisGroup.getChildCount(), new LayoutParams(width, height));
317+
thisGroup.addView(refreshHeader.getView(), thisGroup.getChildCount(), lp);
300318
}
301319
this.mRefreshHeader = header;
302320
this.mWrappedInternal = header;
@@ -335,6 +353,16 @@ public TwoLevelHeader setEnablePullToCloseTwoLevel(boolean enabled) {
335353
return this;
336354
}
337355

356+
/**
357+
* 设置是否开启
358+
* @param enabled 刷新功能
359+
* @return TwoLevelHeader
360+
*/
361+
public TwoLevelHeader setEnableRefresh(boolean enabled) {
362+
this.mEnableRefresh = enabled;
363+
return this;
364+
}
365+
338366
/**
339367
* 设置触发二楼的白百分比
340368
* @param rate 比率 要求大于 RefreshRate

refresh-header-two-level/src/main/res/values/attrs.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
<attr name="srlFloorRate" format="float"/>
77
<attr name="srlRefreshRate" format="float"/>
88
<attr name="srlFloorDuration" format="integer"/>
9+
<attr name="srlEnableRefresh" format="boolean"/>
910
<attr name="srlEnableTwoLevel" format="boolean"/>
1011
<attr name="srlEnablePullToCloseTwoLevel" format="boolean"/>
1112
</declare-styleable>

refresh-header/build.gradle

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,11 @@ dependencies {
3333
compileOnly 'com.android.support:support-annotations:28.0.0'
3434
compileOnly 'com.android.support:support-v4:28.0.0'
3535
compileOnly project(':refresh-layout')
36-
api project(':refresh-drawable-path')
37-
api project(':refresh-header-material')
36+
compileOnly project(':refresh-drawable-path')
37+
compileOnly project(':refresh-header-material')
38+
39+
compileOnly project(':refresh-layout-kernel')
40+
compileOnly project(':refresh-header-falsify')
3841
}
3942

4043
//publish {

0 commit comments

Comments
 (0)