这是一个例子,不是解决方案。在这个例子中,我弄了一个自定义scrollview,当在X轴方向上滚动的时候就会返回错误(表明事件还没有被处理,应该被传递到下一个视图。)
public class CustomScrollView extends ScrollView {
private GestureDetector mGestureDetector;
View.OnTouchListener mGestureListener;
public CustomScrollView(Context context, AttributeSet attrs) {
super(context, attrs);
mGestureDetector = new GestureDetector(new YScrollDetector());
setFadingEdgeLength(0);
}
@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
return super.onInterceptTouchEvent(ev) && mGestureDetector.onTouchEvent(ev);
}
// 如果我在x方向滚动,返回错误。
class YScrollDetector extends SimpleOnGestureListener {
@Override
public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) {
if(Math.abs(distanceY) > Math.abs(distanceX)) {
return true;
}
return false;
}
}
}
你需要在你的viewswitcher中的一个特定区域做一些类似的。所以你需要修改基本的viewswitchercomponent,然后再根据你的情况调整。
根据上边的建议,我不建议这么做。如果你看看周围的地图类的应用程序,这个不是一个正常的方法,而且我怀疑是否它能运行流畅,用户交互是怎么样的。当他们想要尽可能多的获得空间的时候,地图是能正常工作的。看一下最基本的地图应用:谷歌导航、google地图等。