Skip to content

Commit 3269f23

Browse files
author
Turing Technologies
committed
Fix scroll bar errors that manifest when margins or padding are added to the recyclerView or its elements. Fixes #123
1 parent 16ae24c commit 3269f23

3 files changed

Lines changed: 16 additions & 9 deletions

File tree

app/build.gradle

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@ android {
2424
}
2525

2626
dependencies {
27-
compile project(':lib')
28-
compile "androidx.recyclerview:recyclerview:1.0.0"
29-
compile 'com.pnikosis:materialish-progress:1.7'
30-
compile "com.google.android.material:material:1.0.0"
31-
compile "androidx.appcompat:appcompat:1.0.0"
27+
implementation project(':lib')
28+
implementation "androidx.recyclerview:recyclerview:1.0.0"
29+
implementation 'com.pnikosis:materialish-progress:1.7'
30+
implementation "com.google.android.material:material:1.0.0"
31+
implementation "androidx.appcompat:appcompat:1.0.2"
3232
}

lib/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
apply plugin: 'com.android.library'
22
//apply plugin: 'kotlin-android'
33

4-
def libVersion = '13.3.1'
4+
def libVersion = '13.3.2'
55

66
android {
77
compileSdkVersion 28

lib/src/main/java/com/turingtechnologies/materialscrollbar/ScrollingUtilities.java

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import androidx.recyclerview.widget.LinearLayoutManager;
2121
import android.util.Log;
2222
import android.view.View;
23+
import android.view.ViewGroup;
2324

2425
/*
2526
* Lots of complicated maths taken mostly from Google.
@@ -58,6 +59,7 @@ void scrollHandleAndIndicator() {
5859
} else {
5960
constant = scrollPosState.rowHeight * scrollPosState.rowIndex;
6061
}
62+
constant += + materialScrollBar.recyclerView.getPaddingTop();
6163
scrollBarY = (int) getScrollPosition();
6264
materialScrollBar.handleThumb.setY(scrollBarY);
6365
materialScrollBar.handleThumb.invalidate();
@@ -144,12 +146,12 @@ int scrollToPositionAtProgress(float touchFraction) {
144146
}
145147

146148
int getAvailableScrollHeight() {
147-
int visibleHeight = materialScrollBar.getHeight();
149+
int visibleHeight = materialScrollBar.recyclerView.getHeight();
148150
int scrollHeight;
149151
if(customScroller != null) {
150-
scrollHeight = materialScrollBar.getPaddingTop() + customScroller.getTotalDepth() + materialScrollBar.getPaddingBottom();
152+
scrollHeight = materialScrollBar.recyclerView.getPaddingTop() + customScroller.getTotalDepth() + materialScrollBar.recyclerView.getPaddingBottom();
151153
} else {
152-
scrollHeight = materialScrollBar.getPaddingTop() + getRowCount() * scrollPosState.rowHeight + materialScrollBar.getPaddingBottom();
154+
scrollHeight = materialScrollBar.recyclerView.getPaddingTop() + getRowCount() * scrollPosState.rowHeight + materialScrollBar.recyclerView.getPaddingBottom();
153155
}
154156
return scrollHeight - visibleHeight;
155157
}
@@ -186,6 +188,11 @@ void getCurScrollState() {
186188
} else {
187189
scrollPosState.rowTopOffset = materialScrollBar.recyclerView.getLayoutManager().getDecoratedTop(child);
188190
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());
189196
}
190197
}
191198

0 commit comments

Comments
 (0)