1

I am using two vertical scroll views(say,parent and child).what is the issue is I am not able to scroll my child view instead it scrolls my whole parent view,is there any way that I can restrict my parent view to scroll when I scroll my child scroll view and vice versa?

need help...thanks in advance..!!

BSavaliya
  • 811
  • 16
  • 25
Asif Sb
  • 755
  • 9
  • 35

4 Answers4

4

You need to handle the touch event to do this effectively

        outerScrollView.setOnTouchListener(new View.OnTouchListener() {

            public boolean onTouch(View v, MotionEvent event) {
                findViewById(R.id.inner_scroll).getParent()
                        .requestDisallowInterceptTouchEvent(false);
                return false;
            }
        });

        innerScrollView.setOnTouchListener(new View.OnTouchListener() {

            public boolean onTouch(View v, MotionEvent event) {
                v.getParent().requestDisallowInterceptTouchEvent(true);
                return false;
            }
        });
Dennis MP
  • 12,084
  • 10
  • 43
  • 61
1

Try this one

Note: Here parentScrollView means Outer ScrollView And childScrollView means Innner ScrollView

parentScrollView.setOnTouchListener(new View.OnTouchListener() {

        @Override
        public boolean onTouch(View v, MotionEvent event) {
        Log.v(TAG, "PARENT TOUCH");

        findViewById(R.id.child_scroll).getParent()
                .requestDisallowInterceptTouchEvent(false);
        return false;
    }
});

childScrollView.setOnTouchListener(new View.OnTouchListener() {

        @Override
        public boolean onTouch(View v, MotionEvent event) {
        Log.v(TAG, "CHILD TOUCH");

        // Disallow the touch request for parent scroll on touch of  child view
        v.getParent().requestDisallowInterceptTouchEvent(true);
        return false;
    }
});
BSavaliya
  • 811
  • 16
  • 25
1

This is better for understanding:

childScrollView.setOnTouchListener(new View.OnTouchListener() {
                @Override
                public boolean onTouch(View v, MotionEvent event) {

                    int action = event.getAction();
                    switch (action) {
                        case MotionEvent.ACTION_DOWN:
                            // Disallow ScrollView to intercept touch events.
                            parentScrollV.requestDisallowInterceptTouchEvent(true);

                            break;

                        case MotionEvent.ACTION_UP:
                            // Allow ScrollView to intercept touch events.
                            parentScrollV.requestDisallowInterceptTouchEvent(false);

                            break;
                    }
                    return false;
                }
            });
M. Usman Khan
  • 4,214
  • 1
  • 52
  • 66
-2

-Here is the SOlution you can find With the descriptionHere.

    m_parentScrollView.setOnTouchListener(new View.OnTouchListener() 
    {
           public boolean onTouch(View p_v, MotionEvent p_event) 
            {
                   m_childScrollView.getParent().requestDisallowInterceptTouchEvent(false);
               //  We will have to follow above for all scrollable contents
               return false;
            }
    });


m_childScrollView.setOnTouchListener(new View.OnTouchListener() 
{
      public boolean onTouch(View p_v, MotionEvent p_event)
       {
          // this will disallow the touch request for parent scroll on touch of child view
           p_v.getParent().requestDisallowInterceptTouchEvent(true);
           return false;
       }
});

// We will have to follow above for all child scrollable contents I

These two methods can solve your answer.

Gopinagh.R
  • 4,666
  • 4
  • 44
  • 59
Hardy
  • 2,541
  • 22
  • 44
  • While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. – Brian White Apr 10 '15 at 05:34
  • @BrianWhite THanks for your suggestion and yes you are right at your point. – Hardy Apr 10 '15 at 05:37