Understanding how to use the OverScroller class

I am studying adding flashing (not color changes) to my project, but even after reading the API docs and a few questions here, I still don’t understand what I need to do to get it working.

According to the OverScroller API: β€œThis class encapsulates scrolling with the ability to exceed the scroll borders. This class is a replacement for the scroller in most cases.”

I had a Scroller object before in my parent class:

public boolean onTouchEvent(MotionEvent ev) { ....// code to calculate deltas if (deltaY != 0 || deltaX != 0) scrollBy(deltaX, deltaY); } 

And I decided to change it to this:

 if (deltaY != 0 || deltaX != 0) overScrollBy(deltaX, deltaY, getScrollX(), getScrollY(), child.getRight() - getWidth(), child.getBottom() - getHeight(), OVERSCROLL_DISTANCE, OVERSCROLL_DISTANCE, false); 

And now scrolling doesn't work at all! fling() works fine as a replacement, but not scrolling ....

In conclusion, I have two questions:

  • Why doesn't scrolling work with overScrollBy ? Should I add extra code to make this work?
  • Why should I call mScroller.fling() and only overScrollBy() ? Why not mScroller.overScrollBy() ? Is it somehow built into the View class?

This may be potentially obvious, but I'm afraid here. Any help would be greatly appreciated, thanks!

+6
source share
1 answer

perhaps because of this?

 public class ViewConfiguration{ ... /** * Max distance in dips to overscroll for edge effects */ private static final int OVERSCROLL_DISTANCE = 0; ... } 
0
source

Source: https://habr.com/ru/post/953716/


All Articles