Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

like image 652
Raghu Mudem Avatar asked Dec 07 '12 07:12

Raghu Mudem


People also ask

How do you find X and Y coordinates on android?

Display display = getWindowManager(). getDefaultDisplay(); Point size = new Point(); display. getSize(size); int maxX = size. x; int maxY = size.

How do you center a view?

To center a view, just drag the handles to all four sides of the parent.

How do I center a view programmatically in android?

You can specify the gravity as center_horizontal, center_vertical and center (which centers both horizontally and vertically). On the child views of the LinearLayout you can specify the layout_gravity property, which also supports center_horizontal, center_vertical and center.

How do I center an image on android?

In LinearLayout , use: android:layout_gravity="center" . In RelativeLayout , use: android:layout_centerInParent="true" .


1 Answers

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

like image 135
Mohsin Naeem Avatar answered Sep 22 '22 16:09

Mohsin Naeem