Android中的dispatchTouchEvent()、onInterceptTouchEvent()和onTouchEvent()

dispatchTouchEvent().onInterceptTouchEvent().onTouchEvent()这几个是触摸时间传递过程中重要的几个方法,

dispathchTouchEvent是处理触摸事件分发,事件大多是从Activity的dispatchTouchEvent开始的,执行super.dispatchTouchEvent(ev),事件向下分发。

onInterceptTouchEvent是viewGroud提供的方法,默认返回false,返回true表示拦截。

onTouchEvent是View中提供的方法,ViewGroup也有这个方法,view中不提供onInterceptTouchEvent,view默认返回true,表示消费了事件。

View,有两个回调函数

public  boolean  dispatchTouchEvent(MotionEvent  ev);

public boolean  onTouchEvent(MotionEvent  ev);

ViewGroup,有三个回调函数

public   boolean  dispatchTouchEvent(MotionEvent ev);

public  boolean  onInterceptTouchEvent(MotionEvent   ev);

public boolean onTouchEvent(MotionEvent  ev);

Activity,有两个回调函数

public boolean  dispatchTouchEvent(MotionEvent  ev);

public boolean  onTouchEvent(MotionEvent ev);

未完待续

posted @ 2017-08-31 15:31  让学习如呼吸一般自然  阅读(241)  评论(0编辑  收藏  举报