时间:2020-10-15 23:17:16 | 栏目:Android代码 | 点击:次
实例如下:
//解决ViewPager和轮播图滑动冲突 @Override public boolean dispatchTouchEvent(MotionEvent ev) { switch (ev.getAction()) { case MotionEvent.ACTION_DOWN: // 让当前viewpager的父控件不去拦截touch事件 getParent().requestDisallowInterceptTouchEvent(true); downX = (int) ev.getX(); downY = (int) ev.getY(); break; case MotionEvent.ACTION_MOVE: int moveX = (int) ev.getX(); int moveY = (int) ev.getY(); if (Math.abs(moveX - downX) >= Math.abs(moveY - downY)) { // 滑动轮播图 getParent().requestDisallowInterceptTouchEvent(true); } else { // 刷新listview getParent().requestDisallowInterceptTouchEvent(false); } break; } return super.dispatchTouchEvent(ev); }