先轉載一篇他們的文章,很有用!!
《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;
}