Android MotionEvent.ACTION\u DOWN未被调用,即使我为其返回true

Android MotionEvent.ACTION\u DOWN未被调用,即使我为其返回true,android,ontouchlistener,motionevent,Android,Ontouchlistener,Motionevent,我的ListView的LinearLayout有一个onTouchListener,我正试图使用ACTION\u DOWN和ACTION\u UP数据来检测用户何时切换到下一个ListView。然而,MotionEvent决不等于ACTION\u DOWN,尽管ACTION\u UP工作得很好。经过大量的谷歌搜索,我能找到的唯一解决方案是在调用事件时返回true,但我已经在这么做了。这是我的onTouchListenercode View.OnTouchListener mTouchListen

我的
ListView
LinearLayout
有一个
onTouchListener
,我正试图使用
ACTION\u DOWN
ACTION\u UP
数据来检测用户何时切换到下一个
ListView
。然而,
MotionEvent
决不等于
ACTION\u DOWN
,尽管
ACTION\u UP
工作得很好。经过大量的谷歌搜索,我能找到的唯一解决方案是在调用事件时返回true,但我已经在这么做了。这是我的
onTouchListener
code

View.OnTouchListener mTouchListener = new View.OnTouchListener() {

        @Override
        public boolean onTouch(View v, MotionEvent event) {
            if (event.getAction() == MotionEvent.ACTION_DOWN) {
                downX = event.getX();
                return true;
            } else if (event.getAction() == MotionEvent.ACTION_UP) {
                upX = event.getX();
                if(userSwipedFarEnough)
                    doStuff()
                return true;
            }
            return false;

        }

    };

根据触摸类型的不同,onTouch会被多次调用,动作\向下动作\向上动作\移动,所有这些都可能同时发生。我会说去掉else if,然后使用if so,它会捕获两个动作

我知道发生了什么,我的listview的scrollview不知何故窃取了动作,所以没有调用它。当我有一个空的listview并且滚动工作时,我意识到了这一点。

我的解决方案是扩展滚动视图:

interface MyScrollViewActionDownListener{
    fun onActionDown()
}

class MyScrollView: ScrollView
{
    private var mActionDownListener: MyScrollViewActionDownListener? = null
    constructor(context: Context, attributeSet: AttributeSet, defStyleAttr: Int): super(context, attributeSet, defStyleAttr)
    constructor(context: Context):super(context)
    constructor(context: Context, attributeSet: AttributeSet):super(context,attributeSet)

    override fun onInterceptTouchEvent(ev: MotionEvent?): Boolean {
        if(ev!!.action == MotionEvent.ACTION_DOWN){
            mActionDownListener?.onActionDown()
        }
        return super.onInterceptTouchEvent(ev)
    }

    fun setActionDownListener(listener: MyScrollViewActionDownListener){
        this.mActionDownListener = listener
    }
}

我尝试了这个,但它并没有解决问题,肯定还有其他问题…但感谢您的回复ID如果(event.getActionMasked()==MotionEvent.ACTION\u DOWN)您在哪个视图上设置了此侦听器?。层次结构中的何处?在所有代码之前尝试一些类似日志的操作奇怪,我删除了我的答案,因为我错了,+1。顺便说一句,您正在将touch listener设置为
视图组
?或者只是一个
视图
?它是一个线性布局视图