Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>None of the solutions found worked "out of the box" for me, probably because my custom view extends <strong>View</strong>, not <strong>ViewGroup</strong>, and thus I can't implement <code>onInterceptTouchEvent</code>.</p> <p>Also calling <code>getParent().requestDisallowInterceptTouchEvent(true)</code> was throwing NPE, or doing nothing at all.</p> <p>Finally this is how I solved the problem:<br> Inside your custom <code>onTouchEvent</code> call <code>requestDisallow...</code> when your view will take care of the event. For example:</p> <pre><code>@Override public boolean onTouchEvent(MotionEvent event) { Point pt = new Point( (int)event.getX(), (int)event.getY() ); if (event.getAction() == MotionEvent.ACTION_DOWN) { if (/*this is an interesting event my View will handle*/) { // here is the fix! now without NPE if (getParent() != null) { getParent().requestDisallowInterceptTouchEvent(true); } clicked_on_image = true; } } else if (event.getAction() == MotionEvent.ACTION_MOVE) { if (clicked_on_image) { //do stuff, drag the image or whatever } } else if (event.getAction() == MotionEvent.ACTION_UP) { clicked_on_image = false; } return true; } </code></pre> <p>Now my custom view works fine, handling some events and letting scrollView catch the ones we don't care about. Found the solution here: <a href="http://android-devblog.blogspot.com.es/2011/01/scrolling-inside-scrollview.html">http://android-devblog.blogspot.com.es/2011/01/scrolling-inside-scrollview.html</a></p> <p>Hope it helps.</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