Skip to content

Commit b695353

Browse files
committed
add set the pull-down refresh resisitance factor interface
1 parent e7d7b3a commit b695353

File tree

2 files changed

+25
-5
lines changed

2 files changed

+25
-5
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,9 @@ task clean(type: Delete) {
4242
* You need to add library dependencies infomation to build.gradle in your module.
4343

4444
```
45-
compile 'com.github.anzaizai:EasyRefreshLayout:1.1.3'
45+
compile 'com.github.anzaizai:EasyRefreshLayout:1.1.4'
4646
```
47-
* last releases version is 1.1.3 can be use
47+
* last releases version is 1.1.4 can be use
4848

4949
## step 3
5050

library/src/main/java/com/ajguan/library/EasyRefreshLayout.java

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
import android.os.Handler;
88
import android.support.v4.view.MotionEventCompat;
99
import android.support.v4.view.ViewCompat;
10-
import android.support.v7.widget.DefaultItemAnimator;
1110
import android.support.v7.widget.GridLayoutManager;
1211
import android.support.v7.widget.LinearLayoutManager;
1312
import android.support.v7.widget.RecyclerView;
@@ -40,6 +39,8 @@ public class EasyRefreshLayout extends ViewGroup {
4039
private static long SHOW_COMPLETED_TIME = 500;
4140
private static long SCROLL_TO_LOADING_DURATION = 500;
4241
private static long SHOW_SCROLL_DOWN_DURATION = 300;
42+
private static double PUll_RESISTANCE = 2;
43+
4344
private State state = State.RESET;
4445

4546
private boolean isEnablePullToRefresh = true;
@@ -139,7 +140,13 @@ public void setRefreshHeadView(View headerView) {
139140

140141
@Override
141142
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
142-
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
143+
//获取父控件高度
144+
// int parentHeight = MeasureSpec.getSize(heightMeasureSpec);
145+
// System.out.println(">>>>>parentHeight = "+parentHeight);
146+
// int expandParentHeight = View.MeasureSpec.makeMeasureSpec(Integer.MAX_VALUE >> 2, View.MeasureSpec.AT_MOST);
147+
// super.onMeasure(widthMeasureSpec, expandParentHeight);
148+
149+
super.onMeasure(widthMeasureSpec,heightMeasureSpec);
143150
if (contentView == null) {
144151
initContentView();
145152
}
@@ -388,7 +395,7 @@ private void moveSpinner(float offsetY) {
388395
float extraOS = nextOffsetTop - totalDragDistance;
389396
float slingshotDist = totalDragDistance;
390397
float tensionSlingshotPercent = Math.max(0, Math.min(extraOS, slingshotDist * 2) / slingshotDist);
391-
float tensionPercent = (float) (tensionSlingshotPercent - Math.pow(tensionSlingshotPercent / 2, 2));
398+
float tensionPercent = (float) (tensionSlingshotPercent - Math.pow(tensionSlingshotPercent / PUll_RESISTANCE, 2));
392399

393400
if (offset > 0) { // 下拉的时候才添加阻力
394401
offset = (int) (offset * (1f - tensionPercent));
@@ -667,6 +674,7 @@ private void initERVH() {
667674
mRecyclerView = (RecyclerView) contentView;
668675
mRecyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
669676

677+
670678
@Override
671679
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
672680
super.onScrolled(recyclerView, dx, dy);
@@ -987,4 +995,16 @@ public void setHideLoadViewAnimatorDuration(long showCompletedTime) {
987995
SHOW_COMPLETED_TIME = showCompletedTime;
988996
}
989997

998+
999+
public static double getPUll_RESISTANCE() {
1000+
return PUll_RESISTANCE;
1001+
}
1002+
1003+
/**
1004+
* Set the pull-down refresh resistance factor
1005+
* @param PUll_RESISTANCE resistance factor
1006+
*/
1007+
public static void setPUll_RESISTANCE(double PUll_RESISTANCE) {
1008+
EasyRefreshLayout.PUll_RESISTANCE = PUll_RESISTANCE;
1009+
}
9901010
}

0 commit comments

Comments
 (0)