求教一个关于滑动冲突的问题

我写了一个HorizontalScrollView里面嵌套一个ListView控件的布局,想解决它们之间的滑动冲突问题,所以重写HorizontalScrollView拦截器代码:

    @Override
    public boolean onInterceptTouchEvent(MotionEvent ev) {
        int x=(int)ev.getX();
        int y=(int)ev.getY();
        switch (ev.getAction()){
            case MotionEvent.ACTION_DOWN:
                intercepter=false;
                Log.d(TAG,"ACTION_DOWN");
                break;
            case MotionEvent.ACTION_MOVE:
                int deltX=x-lastX;
                int deltY=y-lastY;
                Log.d(TAG,"ACTION_MOVE");
                Log.d(TAG,"Math.abs(deltX):"+Math.abs(deltX));
                Log.d(TAG,"Math.abs(deltY):"+Math.abs(deltY));
                if(Math.abs(deltX)>Math.abs(deltY)){
                    intercepter=true;
                }else if(Math.abs(deltX)<Math.abs(deltY)){
                    intercepter=false;
                }
                break;
            case MotionEvent.ACTION_UP:
                Log.d(TAG,"ACTION_UP");
                intercepter=false;
                break;
        }
        lastY=y;
        lastX=x;
        Log.d(TAG,"intercepter:"+intercepter);
        return intercepter;
    }

但是奇怪的是我在HorizontalScrollView区域滑动可正常左右滑动,但只获取到了MotionEvent.ACTION_DOWN事件而完全没有获取MotionEvent.ACTION_MOVE和MotionEvent.ACTION_UP事件。然后我在ListView中上下滑ListView可正常滑动但左右滑不能滑动ScrollView,可此时ScrollView居然获取到了MotionEvent.ACTION_MOVE事件,请问这是什么原因?

以下是在ListView左右滑输出的信息:

2018-12-02 14:09:28.286 24256-24256/io.github.grooters.practicer D/ScrollVieWer: intercepter:true
2018-12-02 14:09:29.740 24256-24256/io.github.grooters.practicer D/ScrollVieWer: intercepter:false
2018-12-02 14:09:29.752 24256-24256/io.github.grooters.practicer D/ScrollVieWer: ACTION_MOVE
2018-12-02 14:09:29.752 24256-24256/io.github.grooters.practicer D/ScrollVieWer: Math.abs(deltX):0
2018-12-02 14:09:29.752 24256-24256/io.github.grooters.practicer D/ScrollVieWer: Math.abs(deltY):0
2018-12-02 14:09:29.752 24256-24256/io.github.grooters.practicer D/ScrollVieWer: intercepter:false
2018-12-02 14:09:29.766 24256-24256/io.github.grooters.practicer D/ScrollVieWer: ACTION_MOVE
2018-12-02 14:09:29.766 24256-24256/io.github.grooters.practicer D/ScrollVieWer: Math.abs(deltX):18
2018-12-02 14:09:29.766 24256-24256/io.github.grooters.practicer D/ScrollVieWer: Math.abs(deltY):10
2018-12-02 14:09:29.766 24256-24256/io.github.grooters.practicer D/ScrollVieWer: intercepter:true

intercepter都为true了应该拦截到了滑动事件 为什么还是不能左右滑动HorizontalScrollView呢 T T

阅读 1k
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题