标签:
一段拦截判断而已. 之前一直误解了一个拦截的描述.导致搞了半天.
结论: onInterceptTouchEvent 返回true,就由本身View的onTouchEvent进行事件消费。
/** 在控件中 左右滑时 强制拦截事件的ViewPager * Created by user on 2016/3/7. */ public class MyViewPager extends ViewPager { private String TAG = "MyViewPager"; private int startX; private int startY; public MyViewPager(Context context, AttributeSet attrs) { super(context, attrs); } public MyViewPager(Context context) { super(context); } @Override public boolean onInterceptTouchEvent(MotionEvent ev) { switch (ev.getAction()){ case MotionEvent.ACTION_DOWN: startX = (int) ev.getRawX(); startY = (int) ev.getRawY(); break; case MotionEvent.ACTION_MOVE: int endX = (int) ev.getRawX(); int endY = (int) ev.getRawY(); if (Math.abs(endX - startX) > Math.abs(endY - startY)) {// 左右滑动 return true; }else{ return super.onInterceptTouchEvent(ev); } } return super.onInterceptTouchEvent(ev); } }
ViewPager 嵌套Listview 让Listview响应 ViewPager 左右滑事件
标签:
原文地址:http://www.cnblogs.com/ImyFen/p/5250068.html