A View's onTouchListener vs onTouchEvent

后端 未结 2 1470
情深已故
情深已故 2021-02-13 06:18

What is the difference between a view\'s onTouchEvent :

public class MyCustomView extends View {
    // THIS :
    @Override
    public boolean on         


        
相关标签:
2条回答
  • 2021-02-13 06:55

    I am not sure if you had found your answer. But I found related questions similar to yours.

    "onTouch works everywhere you want (whether it is in activity or view) as long as you have declared the interface and put the Listener right! On the other hand, onTouchEvent only works inside a View!"

    For scrolling and zooming functionality, I guess onTouchListener will be enough to complete both function (and many more like rotation etc).

    0 讨论(0)
  • 2021-02-13 07:06

    Answer by LeeYiHong is correct, and the other very important thing is what is written at http://developer.android.com/reference/android/view/View.OnTouchListener.html:

    The callback [i.e. View.OnTouchListener -> onTouch(View v, MotionEvent event)] will be invoked before the touch event [i.e. onTouchEvent(MotionEvent)] is given to the view.

    0 讨论(0)
提交回复
热议问题