Activity——ViewGroup——View
1、默认情况
Activity:
@Override
public boolean dispatchTouchEvent(MotionEvent ev) {
Log.d("MainActivity","MainActivity dispatchTouchEvent");
return super.dispatchTouchEvent(ev);
}
@Override
public boolean onTouchEvent(MotionEvent event) {
switch (event.getAction()){
case MotionEvent.ACTION_DOWN:
Log.d("MainActivity","MainActivity onTouchEvent down");
break;
case MotionEvent.ACTION_UP:
Log.d("MainActivity","MainActivity onTouchEvent up");
break;
default:
break;
}
return super.onTouchEvent(event);
}
ViewGroup:
@Override
public boolean dispatchTouchEvent(MotionEvent ev) {
Log.d("MyViewGroup","MyViewGroup dispatchTouchEvent");
return super.dispatchTouchEvent(ev);
}
@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
Log.d("MyViewGroup","MyViewGroup onInterceptTouchEvent");
return super.onInterceptTouchEvent(ev);
}
@Override
public boolean onTouchEvent(MotionEvent event) {
switch (event.getAction()){
case MotionEvent.ACTION_DOWN:
Log.d("MyViewGroup","MyViewGroup onTouchEvent down");
break;
case MotionEvent.ACTION_UP:
Log.d("MyViewGroup","MyViewGroup onTouchEvent up");
break;
default:
break;
}
return super.onTouchEvent(event);
}
View:
@Override
public boolean dispatchTouchEvent(MotionEvent ev) {
Log.d("MyView","MyView dispatchTouchEvent");
return super.dispatchTouchEvent(ev);
}
@Override
public boolean onTouchEvent(MotionEvent event) {
switch (event.getAction()){
case MotionEvent.ACTION_DOWN:
Log.d("MyView","MyView onTouchEvent down");
break;
case MotionEvent.ACTION_UP:
Log.d("MyView","MyView onTouchEvent up");
break;
default:
break;
}
return super.onTouchEvent(event);
}
事件传递:
2、Activity dispatchTouchEvent return true
事件传递:
3、Activity dispatchTouchEvent return false
事件传递:
4、ViewGroup dispatchTouchEvent return true
事件传递:
5、ViewGroup dispatchTouchEvent return false
事件传递:
6、ViewGroup onTouchEvent return true
事件传递:
7、ViewGroup onTouchEvent return false
事件传递:同1
8、ViewGroup onInterceptTouchEvent return true
事件传递:
9、ViewGroup onInterceptTouchEvent return false
事件传递:同1
10、View dispatchTouchEvent return true
事件传递:
11、View dispatchTouchEvent return false
事件传递:
12、View onTouchEvent return true
事件传递:
13、View onTouchEvent return false
事件传递:同1