转:http://www.rapidsnail.com/Tutorial/t/2012/1018/30/15343/the-android-ontouch-and-onclick-conflict-processing.aspx
public boolean onTouch(View V, MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_DOWN) {
X1 = event.getX();
Y1 = event.getY();
}
if (event.getAction() == MotionEvent.ACTION_UP) {
X2 = event.getX();
Y2 = event.getY();
if (Math.abs(X1 - X2) < 6) {
Toast.makeText(getApplicationContext(), "onClick",
Toast.LENGTH_SHORT).show();
return false; // distance is smaller, as the click event
// handling
}
if (Math.abs(X1 - X2) > 60) {// onTouch real events
Toast.makeText(getApplicationContext(), "onTouch",
Toast.LENGTH_SHORT).show();
}
}
return true; // returns, not to execute click events
}
public boolean onTouch(View V, MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_DOWN) {
X1 = event.getX();
Y1 = event.getY();
}
if (event.getAction() == MotionEvent.ACTION_UP) {
X2 = event.getX();
Y2 = event.getY();
if (Math.abs(X1 - X2) < 6) {
Toast.makeText(getApplicationContext(), "onClick",
Toast.LENGTH_SHORT).show();
return false; // distance is smaller, as the click event
// handling
}
if (Math.abs(X1 - X2) > 60) {// onTouch real events
Toast.makeText(getApplicationContext(), "onTouch",
Toast.LENGTH_SHORT).show();
}
}
return true; // returns, not to execute click events
}