Note that there are some explanatory texts on larger screens.

plurals
  1. POCan't get the horizontal fling on a ScrollView within a ViewFlipper to bubble up
    text
    copied!<p>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.</p> <p>Here's the design. The green box is the ScrollView, which should be vertical. </p> <p><img src="https://i.stack.imgur.com/PqZDc.png" alt="enter image description here"></p> <p>Here's the ScrollView:</p> <pre><code>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 &gt; 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; } } } </code></pre> <p>I've been trying to base the solution on the advice here <a href="https://stackoverflow.com/questions/2646028/android-horizontalscrollview-within-scrollview-touch-handling">HorizontalScrollView within ScrollView Touch Handling</a> and here <a href="https://stackoverflow.com/questions/5102993/swipe-fling-tab-changing-in-conjunction-with-scrollview">Swipe/Fling tab-changing in conjunction with ScrollView?</a> 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.</p> <p>Any thoughts?</p> <p>Thanks</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload