簡體   English   中英

OnTouchListener 在導航到另一個片段時不記錄 ACTION_UP

[英]OnTouchListener doesn't record ACTION_UP when navigating to another fragment

在用一根手指按住按鈕並用另一根手指導航到另一個片段時,MotionEvent.ACTION_UP 在下一個片段中抬起手指后不會觸發,或者根本不會觸發。

view.findViewById<Button>(R.id.button).setOnTouchListener(OnTouchListener { _, event ->
    when (event.action) {
        MotionEvent.ACTION_DOWN -> {             // PRESSED
            doAction(true)
            return@OnTouchListener true
        }
        MotionEvent.ACTION_UP -> {                // RELEASED
            doAction(false)
            return@OnTouchListener true
        }
    }
    false
})

我該如何解決這個問題?

嘗試捕捉MotionEvent.ACTION_CANCELACTION_UP表示用戶故意從View中移除手指,在您的情況下手指仍然存在(觸摸屏),但框架可能會在離開Fragment /銷毀View時關閉/取消所有MotionEvent s

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM