Reputation: 805
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.!!
Upvotes: 10
Views: 5379
Reputation: 189
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;
}
});
Upvotes: 8