Como Azlam dijo que se puede utilizar para obtener los View.getLocationInWindow()coordenadas x, y.
Aquí se muestra un ejemplo:
Button button = (Button) findViewById(R.id.yourButtonId);
Point point = getPointOfView(button);
Log.d(TAG, "view point x,y (" + point.x + ", " + point.y + ")");
private Point getPointOfView(View view) {
int[] location = new int[2];
view.getLocationInWindow(location);
return new Point(location[0], location[1]);
}
Bono - Para obtener el punto central de la vista dada:
Point centerPoint = getCenterPointOfView(button);
Log.d(TAG, "view center point x,y (" + centerPoint.x + ", " + centerPoint.y + ")");
private Point getCenterPointOfView(View view) {
int[] location = new int[2];
view.getLocationInWindow(location);
int x = location[0] + view.getWidth()/2;
int y = location[1] + view.getHeight()/2;
return new Point(x, y);
}
espero que el ejemplo todavía puede ser útil a alguien.
** getLocationInWindow (int []) ** y ** getLocationOnScreen (int []) ** tiene el parámetro. ¿Estás seguro de tu idea? – hakiko
@hakkikonu eche un vistazo a mi respuesta para comprender el uso de ** getLocationInWindow (int []) **. –