先转载一篇他们的文章,很有用!!
《Android 编程下 Touch 事件的分发和消费机制》
http://blog.csdn.net/hopehe888999/article/details/17241741
在ViewPager中添加该事件处理
// 滑动距离及坐标
private float xDistance, yDistance, xLast, yLast;
@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
Log.e("父", "onInterceptTouchEvent");
switch (ev.getAction()) {
case MotionEvent.ACTION_DOWN:
xDistance = yDistance = 0f;
xLast = ev.getX();
yLast = ev.getY();
break;
case MotionEvent.ACTION_MOVE:
final float curX = ev.getX();
final float curY = ev.getY();
xDistance += Math.abs(curX - xLast);
yDistance += Math.abs(curY - yLast);
xLast = curX;
yLast = curY;
if (xDistance > yDistance) {
return true;
}
}
return false;
}