ListView 添加viewPager为header时,viewPager滑动失去焦点的解决办法

设置ViewPager的onTouch事件,代码如下:


viewPager.setOnTouchListener(new OnTouchListener() {
      @Override
      public boolean onTouch(View v, MotionEvent event) {
        PointF downP = new PointF();
        PointF curP = new PointF();
        int act = event.getAction();
        if(act == MotionEvent.ACTION_DOWN || act == MotionEvent.ACTION_MOVE || act == MotionEvent.ACTION_UP){
          ((ViewGroup) v).requestDisallowInterceptTouchEvent(true);
          if (downP.x == curP.x && downP.y == curP.y) {
            return false;
          }
        }
        return false;
      }
    });



你可能感兴趣的:(ListView 添加viewPager为header时,viewPager滑动失去焦点的解决办法)