I\'m trying to put a ScrollView inside another ScrollView and I tried the answers found on this site but it still doesn\'t seems to work completely. Here is the XML:
Here is a possible solution which works fine with ScrollView and ListView inside a ScrollView. ScrollView Inside ScrollView
you can not use two Scrollview inside Scrollview OS get confuse which one have to scroll so your activity hang so do not use like this
use this custom scrollview as inner scrollview:
public class TouchMeScrollView extends ScrollView {
public TouchMeScrollView(Context context) {
super(context);
}
public TouchMeScrollView(Context context, AttributeSet attrs) {
super(context, attrs);
}
public TouchMeScrollView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public TouchMeScrollView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);
}
@Override
public boolean onTouchEvent(MotionEvent ev) {
requestDisallowInterceptTouchEvent(true);
return super.onTouchEvent(ev);
}
}
check this link which shows that how to use two widget with scroll functionality in same activity. check this below code in that.
parentScroll.setOnTouchListener(new View.OnTouchListener() {
public boolean onTouch(View v, MotionEvent event) {
Log.v("PARENT", "PARENT TOUCH");
findViewById(R.id.child_scroll).getParent()
.requestDisallowInterceptTouchEvent(false);
return false;
}
});
childScroll.setOnTouchListener(new View.OnTouchListener() {
public boolean onTouch(View v, MotionEvent event) {
Log.v("CHILD", "CHILD TOUCH");
// Disallow the touch request for parent scroll on touch of
// child view
v.getParent().requestDisallowInterceptTouchEvent(true);
return false;
}
});
I'm almost sure it is impossible:
How android handles touch events:
Parent gets event and decides if it has to handle it or if it should let handle it to the child;
so,if a scrollview handles the touch, the one which handles it, is always the parent one
http://developer.android.com/training/gestures/viewgroup.html
personally i don't know if is there a way to understand what is touched behind the parent scrollview to see if it is another scrollview and let it handle the movement
You should use NestedScrollView.
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<!-- -->
</android.support.v4.widget.NestedScrollView>