|
7 | 7 | import android.os.Handler;
|
8 | 8 | import android.support.v4.view.MotionEventCompat;
|
9 | 9 | import android.support.v4.view.ViewCompat;
|
10 |
| -import android.support.v7.widget.DefaultItemAnimator; |
11 | 10 | import android.support.v7.widget.GridLayoutManager;
|
12 | 11 | import android.support.v7.widget.LinearLayoutManager;
|
13 | 12 | import android.support.v7.widget.RecyclerView;
|
@@ -40,6 +39,8 @@ public class EasyRefreshLayout extends ViewGroup {
|
40 | 39 | private static long SHOW_COMPLETED_TIME = 500;
|
41 | 40 | private static long SCROLL_TO_LOADING_DURATION = 500;
|
42 | 41 | private static long SHOW_SCROLL_DOWN_DURATION = 300;
|
| 42 | + private static double PUll_RESISTANCE = 2; |
| 43 | + |
43 | 44 | private State state = State.RESET;
|
44 | 45 |
|
45 | 46 | private boolean isEnablePullToRefresh = true;
|
@@ -139,7 +140,13 @@ public void setRefreshHeadView(View headerView) {
|
139 | 140 |
|
140 | 141 | @Override
|
141 | 142 | 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); |
143 | 150 | if (contentView == null) {
|
144 | 151 | initContentView();
|
145 | 152 | }
|
@@ -388,7 +395,7 @@ private void moveSpinner(float offsetY) {
|
388 | 395 | float extraOS = nextOffsetTop - totalDragDistance;
|
389 | 396 | float slingshotDist = totalDragDistance;
|
390 | 397 | 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)); |
392 | 399 |
|
393 | 400 | if (offset > 0) { // 下拉的时候才添加阻力
|
394 | 401 | offset = (int) (offset * (1f - tensionPercent));
|
@@ -667,6 +674,7 @@ private void initERVH() {
|
667 | 674 | mRecyclerView = (RecyclerView) contentView;
|
668 | 675 | mRecyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
|
669 | 676 |
|
| 677 | + |
670 | 678 | @Override
|
671 | 679 | public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
|
672 | 680 | super.onScrolled(recyclerView, dx, dy);
|
@@ -987,4 +995,16 @@ public void setHideLoadViewAnimatorDuration(long showCompletedTime) {
|
987 | 995 | SHOW_COMPLETED_TIME = showCompletedTime;
|
988 | 996 | }
|
989 | 997 |
|
| 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 | + } |
990 | 1010 | }
|
0 commit comments