Asif Sb
Asif Sb

Reputation: 805

Two nested vertical scroll views in android

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..!!

Upvotes: 1

Views: 3082

Answers (3)

Hardy
Hardy

Reputation: 2606

-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.

Upvotes: -2

Deniz
Deniz

Reputation: 12530

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;
            }
        });

Upvotes: 4

BSavaliya
BSavaliya

Reputation: 827

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;
    }
});

Upvotes: 1

Related Questions