android ontouch onclick 冲突解决:设置touch返回值为flase
mMouseview.setOnClickListener(new MouseClick());
mMouseview.setOnTouchListener(new MouseTouch());
class MouseClick implements View.OnClickListener{
@Override
public void onClick(View v) {
if (Math.abs(mCurx - mStartx) < 5 && Math.abs(mCurx - mStartx) < 5) { }
}
}
@Override
public boolean onMouseTouch(View v, MotionEvent event, int index) {
if (event.getAction() == MotionEvent.ACTION_DOWN) {
mStartx = (int) (event.getX());
mStarty = (int) (event.getY());
mCurx = mStartx;
mCury = mStarty;
mPrex = mStartx;
mPrey = mStarty;
mMouseview.invalidate();
} else if (event.getAction() == MotionEvent.ACTION_UP) {
mCurx = (int) (event.getX());
mCury = (int) (event.getY());
} else if (event.getAction() == MotionEvent.ACTION_MOVE) {
mCurx = (int) (event.getX());
mCury = (int) (event.getY());
int offsetx = mCurx - mPrex;
int offsety = mCury - mPrey;
if (Math.abs(offsetx) > 0 || Math.abs(offsety) > 0) {
mPrex = mCurx;
mPrey = mCury;
if (mProjectionMouseService == null) {
return false;
}
mMouseview.invalidate();
}
return false;
}
网友评论