我不得不改进 Deepthi 的解决方案,因为它对我不起作用;我猜是因为我的子滚动视图充满了视图(我的意思是子视图使用了所有滚动视图绘图空间)。为了使其功能齐全,我还必须禁止在触摸子滚动视图中的所有子视图时对父滚动的触摸请求:
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;
}
});
}
}
}