我正在努力實現以下功能:無論MotionEvent目標如何,調用按鈕的onClick(...)回調
我的ViewGroup中有N個按鈕。
------------
| button 1 |
------------
| button 2 |
------------
| ... |
------------
| button N |
------------
用戶按下button 1
(MotionEvent.ACTION_DOWN
),那麼他將他的手指button N
(MotionEvent.ACTION_MOVE
),然後他鬆開手指(MotionEvent.ACTION_UP
)。
- 我想強調任何按鈕,在其用戶移動他的手指 (懸停高亮)
- 我想要的
button N
onClick(...)
回調被調用時,用戶釋放他的手指上button N
我試圖爲每個按鈕設置onTouchListener
,並且似乎首先被觸摸的按鈕接收所有3個提到的操作(MotionEvent.ACTION_DOWN
,MotionEvent.ACTION_MOVE
和MotionEvent.ACTION_UP
)。
我也想過通過覆蓋onInterceptTouchEvent(MotionEvent)
按鈕父母的方法ViewGroup
來實現功能。這可能是可能的,但似乎沒有辦法檢測從MotionEvent
傳遞給onInterceptTouchEvent(MotionEvent)
方法的子視圖。
您是否有任何提示實現所描述的功能?