//
主Activity: InterceptTouchStudyActivity.java:
public
class
InterceptTouchStudyActivity
extends
Activity {
static
final
String TAG
=
"
ITSActivity
"
;
TextView tv;
/**
Called when the activity is first created.
*/
@Override
public
void
onCreate(Bundle savedInstanceState) {
super
.onCreate(savedInstanceState);
setContentView(R.layout.layers_touch_pass_test);
}
}
//
LayoutView1.java:
public
class
LayoutView1
extends
LinearLayout {
private
final
String TAG
=
"
LayoutView1
"
;
public
LayoutView1(Context context, AttributeSet attrs) {
super
(context, attrs);
Log.d(TAG,TAG);
}
@Override
public
boolean
onInterceptTouchEvent(MotionEvent ev) {
int
action
=
ev.getAction();
switch
(action){
case
MotionEvent.ACTION_DOWN:
Log.d(TAG,
"
onInterceptTouchEvent action:ACTION_DOWN
"
);
//
return true;
break
;
case
MotionEvent.ACTION_MOVE:
Log.d(TAG,
"
onInterceptTouchEvent action:ACTION_MOVE
"
);
break
;
case
MotionEvent.ACTION_UP:
Log.d(TAG,
"
onInterceptTouchEvent action:ACTION_UP
"
);
break
;
case
MotionEvent.ACTION_CANCEL:
Log.d(TAG,
"
onInterceptTouchEvent action:ACTION_CANCEL
"
);
break
;
}
return
false
;
}
@Override
public
boolean
onTouchEvent(MotionEvent ev) {
int
action
=
ev.getAction();
switch
(action){
case
MotionEvent.ACTION_DOWN:
Log.d(TAG,
"
onTouchEvent action:ACTION_DOWN
"
);
break
;
case
MotionEvent.ACTION_MOVE:
Log.d(TAG,
"
onTouchEvent action:ACTION_MOVE
"
);
break
;
case
MotionEvent.ACTION_UP:
Log.d(TAG,
"
onTouchEvent action:ACTION_UP
"
);
break
;
case
MotionEvent.ACTION_CANCEL:
Log.d(TAG,
"
onTouchEvent action:ACTION_CANCEL
"
);
break
;
}
return
true
;
}
@Override
protected
void
onLayout(
boolean
changed,
int
l,
int
t,
int
r,
int
b) {
//
TODO Auto-generated method stub
super
.onLayout(changed, l, t, r, b);
}
@Override
protected
void
onMeasure(
int
widthMeasureSpec,
int
heightMeasureSpec) {
//
TODO Auto-generated method stub
super
.onMeasure(widthMeasureSpec, heightMeasureSpec);
}
}
//
LayoutView2.java:
public
class
LayoutView2
extends
LinearLayout {
private
final
String TAG
=
"
LayoutView2
"
;
public
LayoutView2(Context context, AttributeSet attrs) {
super
(context, attrs);
Log.d(TAG,TAG);
}
@Override
public
boolean
onInterceptTouchEvent(MotionEvent ev) {
int
action
=
ev.getAction();
switch
(action){
case
MotionEvent.ACTION_DOWN:
Log.d(TAG,
"
onInterceptTouchEvent action:ACTION_DOWN
"
);
break
;
case
MotionEvent.ACTION_MOVE:
Log.d(TAG,
"
onInterceptTouchEvent action:ACTION_MOVE
"
);
break
;
case
MotionEvent.ACTION_UP:
Log.d(TAG,
"
onInterceptTouchEvent action:ACTION_UP
"
);
break
;
case
MotionEvent.ACTION_CANCEL:
Log.d(TAG,
"
onInterceptTouchEvent action:ACTION_CANCEL
"
);
break
;
}
return
false
;
}
@Override
public
boolean
onTouchEvent(MotionEvent ev) {
int
action
=
ev.getAction();
switch
(action){
case
MotionEvent.ACTION_DOWN:
Log.d(TAG,
"
onTouchEvent action:ACTION_DOWN
"
);
break
;
case
MotionEvent.ACTION_MOVE:
Log.d(TAG,
"
onTouchEvent action:ACTION_MOVE
"
);
break
;
case
MotionEvent.ACTION_UP:
Log.d(TAG,
"
onTouchEvent action:ACTION_UP
"
);
break
;
case
MotionEvent.ACTION_CANCEL:
Log.d(TAG,
"
onTouchEvent action:ACTION_CANCEL
"
);
break
;
}
return
true
;
}
}
//
MyTextView.java:
public
class
MyTextView
extends
TextView {
private
final
String TAG
=
"
MyTextView
"
;
public
MyTextView(Context context, AttributeSet attrs) {
super
(context, attrs);
Log.d(TAG,TAG);
}
@Override
public
boolean
onTouchEvent(MotionEvent ev) {
int
action
=
ev.getAction();
switch
(action){
case
MotionEvent.ACTION_DOWN:
Log.d(TAG,
"
onTouchEvent action:ACTION_DOWN
"
);
break
;
case
MotionEvent.ACTION_MOVE:
Log.d(TAG,
"
onTouchEvent action:ACTION_MOVE
"
);
break
;
case
MotionEvent.ACTION_UP:
Log.d(TAG,
"
onTouchEvent action:ACTION_UP
"
);
break
;
case
MotionEvent.ACTION_CANCEL:
Log.d(TAG,
"
onTouchEvent action:ACTION_CANCEL
"
);
break
;
}
return
false
;
}
public
void
onClick(View v) {
Log.d(TAG,
"
onClick
"
);
}
public
boolean
onLongClick(View v) {
Log.d(TAG,
"
onLongClick
"
);
return
false
;
}
}