|
20 | 20 | import androidx.recyclerview.widget.LinearLayoutManager; |
21 | 21 | import android.util.Log; |
22 | 22 | import android.view.View; |
| 23 | +import android.view.ViewGroup; |
23 | 24 |
|
24 | 25 | /* |
25 | 26 | * Lots of complicated maths taken mostly from Google. |
@@ -58,6 +59,7 @@ void scrollHandleAndIndicator() { |
58 | 59 | } else { |
59 | 60 | constant = scrollPosState.rowHeight * scrollPosState.rowIndex; |
60 | 61 | } |
| 62 | + constant += + materialScrollBar.recyclerView.getPaddingTop(); |
61 | 63 | scrollBarY = (int) getScrollPosition(); |
62 | 64 | materialScrollBar.handleThumb.setY(scrollBarY); |
63 | 65 | materialScrollBar.handleThumb.invalidate(); |
@@ -144,12 +146,12 @@ int scrollToPositionAtProgress(float touchFraction) { |
144 | 146 | } |
145 | 147 |
|
146 | 148 | int getAvailableScrollHeight() { |
147 | | - int visibleHeight = materialScrollBar.getHeight(); |
| 149 | + int visibleHeight = materialScrollBar.recyclerView.getHeight(); |
148 | 150 | int scrollHeight; |
149 | 151 | if(customScroller != null) { |
150 | | - scrollHeight = materialScrollBar.getPaddingTop() + customScroller.getTotalDepth() + materialScrollBar.getPaddingBottom(); |
| 152 | + scrollHeight = materialScrollBar.recyclerView.getPaddingTop() + customScroller.getTotalDepth() + materialScrollBar.recyclerView.getPaddingBottom(); |
151 | 153 | } else { |
152 | | - scrollHeight = materialScrollBar.getPaddingTop() + getRowCount() * scrollPosState.rowHeight + materialScrollBar.getPaddingBottom(); |
| 154 | + scrollHeight = materialScrollBar.recyclerView.getPaddingTop() + getRowCount() * scrollPosState.rowHeight + materialScrollBar.recyclerView.getPaddingBottom(); |
153 | 155 | } |
154 | 156 | return scrollHeight - visibleHeight; |
155 | 157 | } |
@@ -186,6 +188,11 @@ void getCurScrollState() { |
186 | 188 | } else { |
187 | 189 | scrollPosState.rowTopOffset = materialScrollBar.recyclerView.getLayoutManager().getDecoratedTop(child); |
188 | 190 | scrollPosState.rowHeight = child.getHeight(); |
| 191 | + if (child.getLayoutParams() instanceof ViewGroup.MarginLayoutParams) { |
| 192 | + scrollPosState.rowHeight += ((ViewGroup.MarginLayoutParams)child.getLayoutParams()).topMargin; |
| 193 | + scrollPosState.rowHeight += ((ViewGroup.MarginLayoutParams)child.getLayoutParams()).bottomMargin; |
| 194 | + } |
| 195 | + System.out.println(child.getHeight()); |
189 | 196 | } |
190 | 197 | } |
191 | 198 |
|
|
0 commit comments