Search code examples
androidscrollgesture

Scroll a scroll View Manually in program with gesturesDetector?


I have 2 scrollable views above and below like 2 blocks. Both have to be scrolled. Now I want to scroll both of them with the same gesture on scrolling and not individually.I am not using Toolbars or Collapsable Toolbar. I have created a Parent Relative Layout class and have overriden to get all the ScrollEvents with Gesture Detector. But I don't know how to scroll the views.

public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY)

Now from here I don't know how to scroll a particular scroll view smoothly. I know default implementation does it but I am not using the default implementations. I can use

scrollView.scrollTo();

but what values to pass and how to do it smoothly I don't know. Please Help.


Solution

  • The ScrollView has a method smoothScrollTo(int x, int y) its like scrollTo(int, int), but scroll smoothly instead of immediately.

    public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY){
         scrollview.smoothScrollTo(distanceX, distanceY);
    }