Center of the view after rotation or scale

871 views Asked by At

I am trying to find the center of a view. For non-rotated view the value is correct, but for rotated view it's not correct as the centre(0,0) is rotating. In the case of scaling the width and height is keep constant even after zooming

I am using the following formula to calculate the center.

 int[] location = new int[2];
 childView.getLocationOnScreen(location);
 int xLocation = location[0] + childView.getWidth() / 2;
 int yLocation = location[1] + childView.getHeight() / 2 

from getGlobalVisibleRect i get the rect of visible part only

1

There are 1 answers

0
Bohdan Oliynyk On

https://developer.android.com/reference/android/view/View#getHitRect(android.graphics.Rect)

This method will return you Rect(considering rotation and scale) within its parent view