Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to stop the scrolling of parent scroll view when child scroll view is scrolled in android?

Tags:

android

scroll

I know we can use touchlisteners for both scroll view,like

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

what I am facing is my child scroll view is not the immediate child to the parent scroll view.In this v.getParent() is not working and when I touch and try to scroll my child scroll view the whole main scroll is scrolling.

Positions of my scroll views in my layout(views are dynamically created so I need to go with so much layouts)

linearLayout
  ParentscrollView(0)
          linearLayout(0)
              relativeLayout(0)
                       TextView(0)
              relativeLayout(1)
                    childScrollView(0)

need help..Thanks in advance.!!

like image 762
Asif Sb Avatar asked Apr 27 '15 07:04

Asif Sb


People also ask

How do I stop NestedScrollView scrolling?

setnestedscrollingenabled set it to false. try this one add property in recyclerview android:descendantFocusability="blocksDescendants" .

What is nested scroll view?

NestedScrollView is just like ScrollView , but it supports acting as both a nested scrolling parent and child on both new and old versions of Android. Nested scrolling is enabled by default.

How do I get scroll view with match parent?

Try adding android:fillViewport="true"to your ScrollView To work around this, you need to use the ScrollView attribute called android:fillViewport. When set to true, this attribute causes the scroll view's child to expand to the height of the ScrollView if needed.


1 Answers

Isn't findViewById() for parent scroll view id not working?

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
    findViewById(parentLayouttId).requestDisallowInterceptTouchEvent(true);
    return false;
    }
});
like image 104
Sachin Kottary Avatar answered Oct 08 '22 22:10

Sachin Kottary