Button myButton = findViewById(R.id.my_button); int[] coordinates = new int[2]; myButton.getLocationOnScreen(coordinates); int x = coordinates[0]; int y = coordinates[1];
ImageView myImage = findViewById(R.id.my_image); int[] coordinates = new int[2]; myImage.getLocationOnScreen(coordinates); int x = coordinates[0]; int y = coordinates[1];This example demonstrates how to get the screen coordinates (x, y) of an ImageView view called "myImage". The coordinates are retrieved using the getLocationOnScreen method and are stored in an integer array called "coordinates". Package Library: android.view