Skip to content

Commit e2b0f12

Browse files
Merge pull request #6 from dimbslmh/master
Fix for handle is not smooth issue
2 parents 078a918 + 469ad44 commit e2b0f12

File tree

2 files changed

+17
-31
lines changed

2 files changed

+17
-31
lines changed

app/build.gradle

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
apply plugin: 'com.android.application'
22

33
android {
4-
compileSdkVersion 22
5-
buildToolsVersion "22.0.1"
4+
compileSdkVersion 23
5+
buildToolsVersion "23.0.1"
66

77
defaultConfig {
88
applicationId "com.lb.lollipopcontactsrecyclerviewfastscroller"
99
minSdkVersion 11
10-
targetSdkVersion 22
10+
targetSdkVersion 23
1111
versionCode 1
1212
versionName "1.0"
1313
}
@@ -21,6 +21,6 @@ android {
2121

2222
dependencies {
2323
compile fileTree(dir: 'libs', include: ['*.jar'])
24-
compile 'com.android.support:recyclerview-v7:21.0.3'
25-
compile 'com.android.support:appcompat-v7:21.0.3'
24+
compile 'com.android.support:recyclerview-v7:23.0.1'
25+
compile 'com.android.support:appcompat-v7:23.0.1'
2626
}

app/src/main/java/com/lb/lollipop_contacts_recyclerview_fast_scroller/FastScroller.java

Lines changed: 12 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,13 @@
1717

1818
import com.lb.lollipopcontactsrecyclerviewfastscroller.R;
1919

20-
import static android.support.v7.widget.RecyclerView.OnScrollListener;
21-
2220
public class FastScroller extends LinearLayout{
2321
private static final int BUBBLE_ANIMATION_DURATION=100;
2422
private static final int TRACK_SNAP_RANGE=5;
2523

2624
private TextView bubble;
2725
private View handle;
2826
private RecyclerView recyclerView;
29-
private final ScrollListener scrollListener=new ScrollListener();
3027
private int height;
3128

3229
private ObjectAnimator currentAnimator=null;
@@ -98,7 +95,18 @@ public boolean onTouchEvent(@NonNull MotionEvent event)
9895
public void setRecyclerView(RecyclerView recyclerView)
9996
{
10097
this.recyclerView=recyclerView;
101-
recyclerView.setOnScrollListener(scrollListener);
98+
RecyclerView.OnScrollListener onScrollListener = new RecyclerView.OnScrollListener()
99+
{
100+
@Override
101+
public void onScrolled(final RecyclerView recyclerView, final int dx, final int dy)
102+
{
103+
if (handle.isSelected())
104+
return;
105+
float proportion = (float) recyclerView.computeVerticalScrollOffset() / ((float) recyclerView.computeVerticalScrollRange() - height);
106+
setBubbleAndHandlePosition(height * proportion);
107+
}
108+
};
109+
recyclerView.addOnScrollListener(onScrollListener);
102110
}
103111

104112
private void setRecyclerViewPosition(float y)
@@ -115,7 +123,6 @@ else if(handle.getY()+handle.getHeight()>=height-TRACK_SNAP_RANGE)
115123
proportion=y/(float)height;
116124
int targetPos=getValueInRange(0,itemCount-1,(int)(proportion*(float)itemCount));
117125
((LinearLayoutManager)recyclerView.getLayoutManager()).scrollToPositionWithOffset(targetPos,0);
118-
// recyclerView.oPositionWithOffset(targetPos);
119126
String bubbleText=((BubbleTextGetter)recyclerView.getAdapter()).getTextToShowInBubble(targetPos);
120127
bubble.setText(bubbleText);
121128
}
@@ -169,25 +176,4 @@ public void onAnimationCancel(Animator animation)
169176
});
170177
currentAnimator.start();
171178
}
172-
173-
private class ScrollListener extends OnScrollListener{
174-
@Override
175-
public void onScrolled(RecyclerView rv,int dx,int dy)
176-
{
177-
View firstVisibleView=recyclerView.getChildAt(0);
178-
int firstVisiblePosition=recyclerView.getChildPosition(firstVisibleView);
179-
int visibleRange=recyclerView.getChildCount();
180-
int lastVisiblePosition=firstVisiblePosition+visibleRange;
181-
int itemCount=recyclerView.getAdapter().getItemCount();
182-
int position;
183-
if(firstVisiblePosition==0)
184-
position=0;
185-
else if(lastVisiblePosition==itemCount)
186-
position=itemCount;
187-
else
188-
position=(int)(((float)firstVisiblePosition/(((float)itemCount-(float)visibleRange)))*(float)itemCount);
189-
float proportion=(float)position/(float)itemCount;
190-
setBubbleAndHandlePosition(height*proportion);
191-
}
192-
}
193179
}

0 commit comments

Comments
 (0)