|
7 | 7 | import android.support.v7.widget.LinearLayoutManager; |
8 | 8 | import android.support.v7.widget.RecyclerView; |
9 | 9 | import android.support.v7.widget.StaggeredGridLayoutManager; |
| 10 | +import android.util.Log; |
10 | 11 |
|
11 | 12 | public class ScrollMoreListener extends RecyclerView.OnScrollListener { |
12 | 13 |
|
@@ -41,7 +42,7 @@ private int getLastVisibleItem(int[] lastVisibleItemPositions) { |
41 | 42 |
|
42 | 43 | @Override |
43 | 44 | public void onScrolled(RecyclerView recyclerView, int dx, int dy) { |
44 | | - //setStackFromEnd(); |
| 45 | + setStackFromEnd(); |
45 | 46 | if (mListener != null) { |
46 | 47 | int lastVisibleItemPosition = 0; |
47 | 48 | int firstVisibleItemPosition = 0; |
@@ -92,26 +93,36 @@ public void handleMessage(Message msg) { |
92 | 93 | } catch (Exception e) { |
93 | 94 | e.printStackTrace(); |
94 | 95 | } |
95 | | - } else if(msg.what == 2){ |
| 96 | + } else if (msg.what == 2) { |
96 | 97 | try { |
97 | 98 | ll.setStackFromEnd(true); |
98 | 99 | } catch (Exception e) { |
99 | 100 | e.printStackTrace(); |
100 | 101 | } |
101 | 102 | } |
| 103 | + lastTime = System.currentTimeMillis(); |
102 | 104 | } |
103 | 105 | }; |
104 | 106 | LinearLayoutManager ll; |
| 107 | + long lastTime = 0L; |
| 108 | + |
105 | 109 | void setStackFromEnd() { |
| 110 | + long current = System.currentTimeMillis(); |
| 111 | + |
| 112 | + Log.w("setStackFromEnd", "setStackFromEnd:" + (current - lastTime)); |
| 113 | + if (current - lastTime < 500L) { |
| 114 | + return; |
| 115 | + } |
| 116 | + |
106 | 117 | if (mLayoutManager instanceof LinearLayoutManager) { |
107 | 118 | ll = (LinearLayoutManager) mLayoutManager; |
108 | 119 | if (ll.getStackFromEnd()) { |
109 | 120 | if (ll.getChildCount() < mLayoutManager.getItemCount()) { |
110 | | - handler.sendEmptyMessageDelayed(1,150); |
| 121 | + handler.sendEmptyMessageDelayed(1, 150); |
111 | 122 | } |
112 | 123 | } else { |
113 | 124 | if (ll.getChildCount() >= mLayoutManager.getItemCount()) { |
114 | | - handler.sendEmptyMessageDelayed(2,150); |
| 125 | + handler.sendEmptyMessageDelayed(2, 150); |
115 | 126 | } |
116 | 127 | } |
117 | 128 | } |
|
0 commit comments