Touch Scroll on View Flipper in Android?

Praveen picture Praveen · Jul 8, 2010 · Viewed 19.8k times · Source

I have to achieve that the Touch Scroll on the ViewFlipper. For Example. I have two Images. At First, ViewFlipper shows an First Image. Now I Flung the view from right to left. The First Image view Slide out left and the Second Slide in from Left. I can achieve it By this Post. But I want to Scroll the image. That is, on the Action_Move Event I want to do Touch Scroll. For Example, when I move the touch from right to left it will flung how much the touch moves. on that time the output should show both images partly.

How to do that? What I have to measure the Screen levels(height & width). Example codes are more helpful.

Answer

Pavan picture Pavan · Feb 8, 2011

If you need to detect scroll on only viewflipper which is not occupying entire screen, then try the below

gestureDetector = new GestureDetector(new MyGestureDetector());

viewFlipper.setOnTouchListener(new View.OnTouchListener() {

        @Override
        public boolean onTouch(View v, MotionEvent event) {
            if (gestureDetector.onTouchEvent(event)) {
                return false;
            }
            return true;
        }
  });

and MyGestureDetector will be same as in http://www.codeshogun.com/blog/2009/04/16/how-to-implement-swipe-action-in-android/