Update: I figured this out. On my ScrollView, I needed to override the onInterceptTouchEvent method to only intercept the touch event if the Y motion is > the X motion. It seems like the default behavior of a ScrollView is to intercept the touch event whenever there is ANY Y motion.So with the fix, the ScrollView will only intercept the event if the user is deliberately scrolling in the Y direction and in that case pass off the ACTION_CANCEL to the children.
Here is the code for my Scroll View class that contains the HorizontalScrollView: public class CustomScrollView extends ScrollView { private GestureDetector gestureDetector; View. OnTouchListener gestureListener; public CustomScrollView(Context context, AttributeSet attrs) { super(context, attrs); gestureDetector = new GestureDetector(new YScrollDetector()); setFadingEdgeLength(0); } @Override public boolean onTouchEvent(MotionEvent ev) { return super. OnTouchEvent(ev); } @Override public boolean onInterceptTouchEvent(MotionEvent ev) { //Call super first because it does some hidden motion event handling boolean result = super.
OnInterceptTouchEvent(ev); //Now see if we are scrolling vertically with the custom gesture detector if (gestureDetector. OnTouchEvent(ev)) { return result; } //If not scrolling vertically (more y than x), don't hijack the event. Else { return false; } } // Return false if we're scrolling in the x direction class YScrollDetector extends SimpleOnGestureListener { @Override public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) { try { if (Math.
Abs(distanceY) > Math. Abs(distanceX)) { return true; } else { return false; } } catch (Exception e) { // nothing } return false; } } }.
You, sir, are a God to me. Thank you very much. – sniurkst Dec 7 '10 at 7:55 Good stuff, very useful for any scrollable view nesting.
Minor points on the code, though: You can actually simplify the entire onIntercept method to just this: return super. OnInterceptTouchEvent(ev) && mGestureDetector. OnTouchEvent(ev); Also, the try/catch in the onScroll is really unnecessary (exactly what exception can be thrown there?); it'd suffice to replace the entire method with return (Math.
Abs(distanceY) > Math. Abs(distanceX)). – Yoni Samlan Sep 15 at 21:17 Great work, thanks!
– Zsombor ErdÅ‘dy-Nagy Oct 26 at 16:29.
Thank you Joel for giving me a clue on how to resolve this problem. I have simplified the code(without need for a GestureDetector) to achieve the same effect: public class VerticalScrollView extends ScrollView { private float xDistance, yDistance, lastX, lastY; public VerticalScrollView(Context context, AttributeSet attrs) { super(context, attrs); } @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 super.
OnInterceptTouchEvent(ev); } }.
Update: I figured this out. On my ScrollView, I needed to override the onInterceptTouchEvent method to only intercept the touch event if the Y motion is > the X motion. It seems like the default behavior of a ScrollView is to intercept the touch event whenever there is ANY Y motion.
So with the fix, the ScrollView will only intercept the event if the user is deliberately scrolling in the Y direction and in that case pass off the ACTION_CANCEL to the children.
Thank you Joel for giving me a clue on how to resolve this problem.
I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.