简体   繁体   中英

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

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM