I want to get the actual X and Y coordinates of an image in ImageView using the touch function.
So far I am only getting the coordinates within the ImageView which is 800x600. My image would mostly have a higher resolution than that. How do I do this?
MainActivity.java
private void addTouchListener(){
ImageView image = findViewById(R.id.result);
image.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View view, MotionEvent motionEvent) {
float x = motionEvent.getX();
float y = motionEvent.getY();
String message = String.format("Coordinates: (%.1f, %.1f)", x, y);
Log.d(MainActivity.DEBUGTAG, message);
return false;
}
});
}
activity_main.xml
<ImageView
android:id="@+id/result"
android:layout_width="330dp"
android:layout_height="250dp"
android:layout_marginTop="150dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
android:scaleType="fitXY"
android:adjustViewBounds="true"
app:srcCompat="@drawable/leaf"
/>