Android: how to tell if a view is scrolling

Posted by Dave on Stack Overflow See other posts from Stack Overflow or by Dave
Published on 2010-03-19T19:53:32Z Indexed on 2010/03/20 0:51 UTC
Read the original article Hit count: 440

Filed under:
|
|

in iPhone, this would be simple---each view has a scrollViewDidScroll method. I am trying to find the equivalent in Android.

My code works, but it isn't giving me what I want. I need to execute code the entire duration that a view is scrolling. So, even though I use OnGestureListener's onScroll method, it only fires when the finger is on the screen (it's not really named correctly---it should be called "onSlide" or "onSwipe", focusing on the gesture rather than the UI animation). It does not continue to fire if the user flicks the view and it is still scrolling for a few moments after the user lifts his finger.

is there a method that is called at every step of the scroll?

public class Scroll extends Activity implements OnGestureListener {

public  WebView         webview;

public  GestureDetector gestureScanner;

public  int         currentYPosition;
public  int         lastYPosition;

public void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);

    webview = new WebView(this);
    setContentView(webview);
    webview.loadUrl("file:///android_asset/Scroll.html");

    gestureScanner = new GestureDetector(this);

    currentYPosition = 0;
    lastYPosition = 0;

}


public boolean onTouchEvent(final MotionEvent me) {
    return gestureScanner.onTouchEvent(me);
}


public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) {
    // I do stuff here.
    return true;
}

© Stack Overflow or respective owner

Related posts about android

Related posts about scroll