Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><a href="https://stackoverflow.com/questions/4490821/scrollview-inside-scrollview/11554823#11554823">Atul Bhardwaj's answer above</a> is the correct way to do it. But in case someone needs to apply it to a ScrollView where you have less control of the parent, I think this is flexible enough and just the way it's supposed to work:</p> <pre><code>private void makeMyScrollSmart() { myScroll.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View __v, MotionEvent __event) { if (__event.getAction() == MotionEvent.ACTION_DOWN) { // Disallow the touch request for parent scroll on touch of child view requestDisallowParentInterceptTouchEvent(__v, true); } else if (__event.getAction() == MotionEvent.ACTION_UP || __event.getAction() == MotionEvent.ACTION_CANCEL) { // Re-allows parent events requestDisallowParentInterceptTouchEvent(__v, false); } return false; } }); } private void requestDisallowParentInterceptTouchEvent(View __v, Boolean __disallowIntercept) { while (__v.getParent() != null &amp;&amp; __v.getParent() instanceof View) { if (__v.getParent() instanceof ScrollView) { __v.getParent().requestDisallowInterceptTouchEvent(__disallowIntercept); } __v = (View) __v.getParent(); } } </code></pre> <p>What the function does is add a touch listener to <code>myScroll</code> that disables the parent's touch intercept when a touch starts in the child, and then enables it back when the touch actually ends. You don't need a reference to the parent <code>ScrollView</code> and it doesn't have to be the immediate parent... it'll travel the display list until it finds it.</p> <p>Best of both worlds, in my opinion.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

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