I have a vertical ScrollView (actually, a custom ScrollView, code below) within a ViewFlipper. The ViewFlipper works fine unless I swipe horizantally over the ScrollView to flip to the previous/next view. The ScrollView itself works correctly.
Here’s the design. The green box is the ScrollView, which should be vertical.

Here’s the ScrollView:
public class SCScrollView extends ScrollView {
private float xDistance, yDistance, lastX, lastY;
GestureDetector gestureDetector = new GestureDetector(new MyGestureDetector());
OnTouchListener gestureListener;
public SCScrollView(Context context, AttributeSet attrs) {
super(context, attrs);
gestureListener = new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
if (gestureDetector.onTouchEvent(event)) {
return true;
}
return false;
}
};
}
@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
switch (ev.getAction()) {
case MotionEvent.ACTION_DOWN:
xDistance = yDistance = 0f;
lastX = ev.getX();
lastY = ev.getY();
break;
case MotionEvent.ACTION_MOVE:
final float curX = ev.getX();
final float curY = ev.getY();
xDistance += Math.abs(curX - lastX);
yDistance += Math.abs(curY - lastY);
lastX = curX;
lastY = curY;
if(xDistance > yDistance)
return false;
}
return false;
//return super.onInterceptTouchEvent(ev);
}
@Override
public boolean onTouchEvent(MotionEvent event) {
super.onTouchEvent(event);
return gestureDetector.onTouchEvent(event);
}
@Override
public boolean dispatchTouchEvent(MotionEvent ev){
gestureDetector.onTouchEvent(ev);
super.dispatchTouchEvent(ev);
return true;
}
/** GestureDetector used to swipe between classes */
class MyGestureDetector extends GestureDetector.SimpleOnGestureListener {
@Override
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
return false;
}
}
}
I’ve been trying to base the solution on the advice here HorizontalScrollView within ScrollView Touch Handling and here Swipe/Fling tab-changing in conjunction with ScrollView? but regardless of what I return from the callbacks, I cannot get the ViewFlipper to see the fling across the ScrollView and frankly, I’m getting lost in the chain of touch and gesture listeners.
Any thoughts?
Thanks
As in the documented said
http://developer.android.com/reference/android/widget/ScrollView.html
So, I need to ask why did you really want to use your custom scrollview?
If you only intend to be able to scroll, you might no need to use it
only RelativeLayout.scrollBy(x,y); is enough
You could look at this link
Scrollview vertical and horizontal in android
EDIT
Ok, So you need to make the gesture detect the fling over the ScrollView.
You could make it in your Activity without making custom ScrollView also
first, you need to
and in your class create gestureDetector
and your ScrollView object, just declared
then, in override onTouch method
and in override onTouchEvent method
now override your onFling method like this
and this is the whole code
ViewFlipperActivity class
and activity_viewflipper.xml