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
  • 809
  • 1
  • 16
  • 26
Asif Sb
  • 785
  • 9
  • 38

3 Answers3

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;
            }
        });
Deniz
  • 12,332
  • 10
  • 44
  • 62
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
  • 809
  • 1
  • 16
  • 26
-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,826
  • 4
  • 44
  • 60
Hardy
  • 2,576
  • 1
  • 23
  • 45
  • 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