Scrollview inside scroll in Android version

I have scrollview inside scrollview. Xml looks like this:

<RelativeLayout .... <ScrollView..... <RelativeLayout .... <Button..... <Button .... <ScrollView <RelativeLayout .... .......... </RelativeLayout> </ScrollView> </RelativeLayout> </ScrollView> </RelativeLayout> 

in the second scroll view without scrolling. may give a solution for this. I tried many solutions on the Internet but did not work.

+7
android
source share
3 answers

Try this code. He works for me.

  parentScrollView.setOnTouchListener(new View.OnTouchListener() { public boolean onTouch(View v, MotionEvent event) { findViewById(R.id.childScrollView).getParent().requestDisallowInterceptTouchEvent(false); return false; } }); childScrollView.setOnTouchListener(new View.OnTouchListener() { public boolean onTouch(View v, MotionEvent event) { // Disallow the touch request for parent scroll on touch of // child view v.getParent().requestDisallowInterceptTouchEvent(true); return false; } });` 
+20
source share

Another solution is to use this class as the parent class

 public class NoInterceptScrollView extends ScrollView { public NoInterceptScrollView(Context context, AttributeSet attrs) { super(context, attrs); } @Override public boolean onInterceptTouchEvent(MotionEvent ev) { return false; } } 
+5
source share

I had to improve the Deepthi solution because it did not work for me; I think because my child scrollview has a lot of views (I mean, child views use the entire scroll space of the view). To make it fully functional, I also had to prohibit the touch request for parent scrolling by touching all kinds of children in the scroll view of the children:

 parentScrollView.setOnTouchListener(new View.OnTouchListener() { public boolean onTouch(View v, MotionEvent event) { findViewById(R.id.childScrollView).getParent().requestDisallowInterceptTouchEvent(false); return false; } }); childScrollView.setOnTouchListener(new View.OnTouchListener() { public boolean onTouch(View v, MotionEvent event) { // Disallow the touch request for parent scroll on touch of // child view v.getParent().requestDisallowInterceptTouchEvent(true); return false; } });` childScrollviewRecursiveLoopChildren(parentScrollView, childScrollView); public void childScrollviewRecursiveLoopChildren(final ScrollView parentScrollView, View parent) { for (int i = ((ViewGroup) parent).getChildCount() - 1; i >= 0; i--) { final View child = ((ViewGroup) parent).getChildAt(i); if (child instanceof ViewGroup) { childScrollviewRecursiveLoopChildren(parentScrollView, (ViewGroup) child); } else { child.setOnTouchListener(new View.OnTouchListener() { public boolean onTouch(View v, MotionEvent event) { // Disallow the touch request for parent scroll on touch of // child view parentScrollView.requestDisallowInterceptTouchEvent(true); return false; } }); } } } 
0
source share

All Articles