How can i get center x,y of my view in android?

Raghu Mudem picture Raghu Mudem · Dec 7, 2012 · Viewed 37.2k times · Source

I am attaching an imageview up on my frame layout. Here i want to get my imageview center co-ordinates. i will use that same co-ordinates to set my imageview in next layout. Please suggest me how to get the center co-ordinates of my imageview.

Thanks in advance

Answer

Mohsin Naeem picture Mohsin Naeem · Dec 7, 2012

centre of the imageView will be

 centreX=imageView.getX() + imageView.getWidth()  / 2;
 centreY=imageView.getY() + imageView.getHeight() / 2;

but make sure you call it after the imageView created