Reputation: 3657
The button is drawn on the canvas via onDraw
. In the following method I am getting the location of the drawn button and detecting a touch inside it. Once it is sensed snapShot();
is called. I've replaced the content of snapShot();
with System.out.println("snapShot(); is called");
. Every touch I constantly get four lines printed out. I don't understand how this method is calling snapShot() for times in a row?
public boolean onTouch(View view, MotionEvent me) {
Resources res = getResources();
Bitmap bitmap = BitmapFactory.decodeResource(res, R.drawable.camera);
DisplayMetrics metrics = getResources().getDisplayMetrics();
int w = metrics.widthPixels;
int h = metrics.heightPixels;
int heightOffset = - bitmap.getHeight() + h;
int widthOffset = w - bitmap.getWidth();
//See if the motion event is on a Marker
if((me.getRawX() >= widthOffset && me.getRawX() < (widthOffset + bitmap.getWidth())
&& me.getRawY() >= heightOffset && me.getRawY() < (heightOffset + bitmap.getHeight())))
{
snapShot();
return true;
}
return super.onTouchEvent(me);
};
Upvotes: 0
Views: 72
Reputation: 14472
Because onTouch is called when your finger goes down, when it moves and when it's lifted. You need to examine MotionEvent to determine what finger is doing what. It can also be very difficult to touch without causing a move event - see touch slop.
Upvotes: 2