1

Background

In the past, I've asked how to create a fast-scroller for the RecyclerView (here), and found a way to add it and I've even published it, including a Github project (here).

The problem

Starting with specific support library version, things got buggy. The library I've made works fine with this :

compile 'com.android.support:recyclerview-v7:21.0.3'
compile 'com.android.support:appcompat-v7:21.0.3'

But not with this one:

compile 'com.android.support:recyclerview-v7:22.2.0'
compile 'com.android.support:appcompat-v7:22.2.0'

Here's a sample of how it used to work:

enter image description here

The bug that occurs is that when dragging the fast-scroller, it (what you drag) jumps from time to time to other places (reported about here).

What I've tried

I tried finding the cause for this, as well as finding what has changed in RecyclerView that could cause this issue.

I've also tried to report about it (here), but Google told me to ask about it here.

Sadly, I couldn't find the reason for this.

The question

How can I fix this issue, and make the code work fine again?

Community
  • 1
  • 1
android developer
  • 114,585
  • 152
  • 739
  • 1,270
  • ` it jumps from time to time to other places` What jumps, the track or the list? How do you track these positions? You should just debug and see why your handle moves, which callback & stack trace you receive etc. – yigit Jul 07 '15 at 21:17
  • @yigit Please check the links I've provided and what I wrote. They have more information in them to put in here. The jumpy behavior is of the fast scroller itself (what you drag). – android developer Jul 07 '15 at 21:35
  • The only useful thing I see there is setBubbleAndHandlePosition is called with a very high value. Briefly checking your source code shows you are getting it from the event but you are ignoring event pointer etc. Probably sth is wrong in your event tracking. I would suggest checking ItemTouchHelper's event handling. – yigit Jul 07 '15 at 22:22
  • @yigit Seems logical. But why would it work on previous versions of the support library, yet now it doesn't? – android developer Jul 07 '15 at 22:34

1 Answers1

1

What a coincidence, I just used your FastScroller and had the same issue, I also use 22.2.0.

My list to test has roughly 150 items and I saw small jumps in the handle and bubble when I scroll slowly.

Some debugging and I found out that when I drag the handle, the method setBubbleAndHandlePosition() is called from onTouch and from onScrolled.

The problem with that is that onScrolled calculates the "perfect" place for the handle based on the top row. That results in a different position than the handle hold by touch.

My solution was pretty simple, I check in onScrolled() if the handle is in "drag" mode by checking for isSelected() and prevent further calculations on onScrolled().

@Override
public void onScrolled(RecyclerView rv, int dx, int dy)
{
    // only react on scroll events when not done by moving the handle by touch
    // prevents nervous jumping of the handle
    if (handle.isSelected())
    {
        return;
    }
    // rest code of onScrolled is unchanged
}

I guess the reason is/was that onScrolled wasn't called below 22.x but is now...

WarrenFaith
  • 57,492
  • 25
  • 134
  • 150
  • So this occurs because 2 methods call to change the position of the handle? The scrolling and the touching? and you made it ignore the scrolling in case the handle is being dragged? – android developer Jul 08 '15 at 12:37
  • It seems to fix this issue, but now it caused a new issue: Try to drag the fast-scroller . Now stop and scroll in the same direction you've dragged. There is a small jump of the scrolling . Sometimes even in the other direction. I wonder why this time it has issues. – android developer Jul 10 '15 at 22:49