I am trying to get the x,y co-ordinates on Touch of Image and on that I want to perform some action. So, can anyone tell me how to get the x,y co-ordinates of Image when it is touched. Thanks In Advance.
My Code -
public class MovableObject extends ImageView implements OnTouchListener{
Bitmap myBmp;
Paint myPaint = new Paint();
int MoveX = 0;
public MovableObject(Context context,int moveObject,Bitmap myBmp) {
super(context);
super.setClickable(true);
this.myBmp = myBmp;
myPaint.setColor(Color.WHITE);
this.MoveX = moveObject;
setOnTouchListener(this);
}
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
canvas.drawBitmap(myBmp, MoveX, 100, myPaint);
}
@Override
public boolean onTouch(View v, MotionEvent event) {
switch (event.getAction() & MotionEvent.ACTION_MASK) {
case MotionEvent.ACTION_DOWN:
System.out.println("down...."+event.getX()+" "+event.getY());
case MotionEvent.ACTION_MOVE:
}
return true;
}
}
By this I am getting the x,y co-ordinates where I click but I want to get the x,y when I click on my Image.