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
Display display = getWindowManager(). getDefaultDisplay(); Point size = new Point(); display. getSize(size); int maxX = size. x; int maxY = size.
To center a view, just drag the handles to all four sides of the parent.
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.
In LinearLayout , use: android:layout_gravity="center" . In RelativeLayout , use: android:layout_centerInParent="true" .
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With