scrollview和viewpager滑动冲突

import android.content.Context;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.widget.ScrollView; /**
* Created by Administrator on 2016/12/6.
*/
public class MyScrollView extends ScrollView {
// 滑动距离及坐标
private float xDistance, yDistance, xLast, yLast; public MyScrollView(Context context, AttributeSet attrs) {
super(context, attrs);
} @Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
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 false;
}
} return super.onInterceptTouchEvent(ev);
}
}

原理就是通过比较X轴和Y轴的滑动距离来判断

上一篇:vue2.0 正确理解Vue.nextTick()的用途


下一篇:Android ScrollView和ListView滑动冲突解决记录