put the desired image on top in the xml of your application. set it invisible or leave ...
replace:
final View touchView2 = findViewById(R.id.ImageView02);
before the class constructor:
ImageView touchView2;
and in the constructor method (onCreate)
touchView2 = (ImageView) findViewById(R.id.ImageView02);
Now configure onTouchEventListener, having received all the touches on the screen. If these coordinates are in the position you like, call the placeImage method with the X and Y coordinates pressed. This method is placed outside the class constructor (onCreate), so the first method below should be right:
@Override public boolean onTouchEvent(MotionEvent event) { super.onTouchEvent(event); int eventAction = event.getAction(); switch(eventAction) { case MotionEvent.ACTION_DOWN: float TouchX = event.getX(); float TouchY = event.getY(); placeImage(TouchX, TouchY); break; } return true; }
now the placeImage method:
private void placeImage(float X, float Y) { int touchX = (int) X; int touchY = (int) Y;
This should be your answer ... now you only need to make the touchView visible:
touchView2.setVisibility(0);
Franc jacobs
source share