AndroidDeveloperLB / LollipopContactsRecyclerViewFastScroller

A sample of how to mimic the way that the contacts app handles a Fast-Scroller for a RecyclerView
Apache License 2.0
540 stars 95 forks source link

Scrollbar jumping when scrolling near to bottom #1

Closed Komoi closed 9 years ago

Komoi commented 9 years ago

Hi, I found out, that there is some issue with scrollbar, when user scrolls by dragging content (not by your scrollbar). Issue is better visible with fewer items (~20). When scrolling near end of list, scrollbar suddenly jumps all way down and then back again. It ends up somewhere in middle when content is scrolled to bottom entirely. Please review this issue - I will try to investigate it too.

AndroidDeveloperLB commented 9 years ago

This is a lollipop issue and Google is aware of it. I've even reported about it not so long ago. I can give you a link to it if you wish. Wonder if they fixed it

Hi, I found out, that there is some issue with scrollbar, when user scrolls by dragging content (not by your scrollbar). Issue is better visible with fewer items (~20). When scrolling near end of list, scrollbar suddenly jumps all way down and then back again. It ends up somewhere in middle when content is scrolled to bottom entirely. Please review this issue - I will try to investigate it too.

— Reply to this email directly or view it on GitHub https://github.com/AndroidDeveloperLB/LollipopContactsRecyclerViewFastScroller/issues/1 .

Komoi commented 9 years ago

I am pretty curious about that bug, please provide me a link. Thank you for very fast response!

AndroidDeveloperLB commented 9 years ago

here's my report: https://code.google.com/p/android/issues/detail?id=166401 and the original: https://code.google.com/p/android/issues/detail?id=159739 but it's not to the bottom. it's to the top.

Komoi commented 9 years ago

I do not think that this issues are the same. I recorded video so you can see how it differs. In my case, bouncing back is not present. When using fast scrolling with scrollbar, everything seems allright. Position in recyclerview is set up flawlesly according to scrollbar. BUT when you try to scroll trough list without using fast scrolling via scrollbar, position of scrollbar is very wierd. On one point (when scrolled very close to list end) it jumps right to bottom and than back up. Also, when list is scrolled to bottom, scrollbar stays somewhere in middle (this "end" position is dependant on number of items in list - its "end" position is lower with more items in view). This is also reason why you can not see this issue with many items in recyclerview. I will try to investigate it more. Please reply with your opinion. video: https://www.dropbox.com/s/5uf9zdno6txld48/bug_HQ.mp4?dl=0

AndroidDeveloperLB commented 9 years ago

I don't understand how it happened. You just do simple scrolling, and things go crazy. Even the fast scroller looks faulty. This is all when there is a small amount of items. When using

Sorry for that. I've re-opened the issue, as this should be fixed. Do you know perhaps the cause for this? Sadly I've made most of it based on the tutorial I've found, so I don't understand everything in the code. Only wanted to fix what I've found.

Komoi commented 9 years ago

I dont really know, but I will try to find it out. Key to solving might be observing and comparing this behaviour with even less items in list.

AndroidDeveloperLB commented 9 years ago

yes, but it seems to happen even with 100 items. :( Sorry for this.

Komoi commented 9 years ago

I added some debugging logging and I probably found an error source. In attached screenshot you can see added logging on the left with highlighted possible problem source, on center there is text editor with copied log events and on the right there is logcat. As you can see, position value rapidly changed even between slightest scroll down (not using fast scroll bar). I will try to fix it and provide fix to you. Screenshot: https://www.dropbox.com/s/l7eulo4dbjw462d/Screenshot%202015-04-29%2023.21.54.png?dl=0

AndroidDeveloperLB commented 9 years ago

Wow thank you. I guess the calculation of where to put the scroller isn't correct. But there is also the fast-scroller side, meaning that when you drag it, it can "ignore" your dragging (meaning it won't scroll on some cases). I assume the calculation is wrong there too.

Komoi commented 9 years ago

Not clean, but good enough solution. Code change is too small to create pull request, here you are, working pretty well:

  if(firstVisiblePosition==0)
    position=0;
  else if(lastVisiblePosition==itemCount)
    position=itemCount;
  else
    position=(int)(((float)firstVisiblePosition/(((float)itemCount-(float)visibleRange)))*(float)itemCount);

Close this issue if fix is good enough for you. Tested with list size 8, 12, 25 and 250.

AndroidDeveloperLB commented 9 years ago

Thank you. Will check it out and patch if it works.

This is for the "onScrolled" method. I think there should also be something for the fastScroller itself, as it didn't always scroll correctly when being dragged.

AndroidDeveloperLB commented 9 years ago

Seems to work, except for the fast scroller dragging.

zengxiangjian commented 9 years ago

case MotionEvent.ACTION_MOVE: recyclerView.setOnScrollListener(null); return true; case MotionEvent.ACTION_CANCEL: recyclerView.setOnScrollListener(scrollListener); return true;

AndroidDeveloperLB commented 9 years ago

@zengxiangjian What is this?