0

I have an ImageView in the center of a constraint layout. I want to get its coordinates in the screen for animation. I have referred similar questions, but I always get 0 as the coordinate.

How can I get the coordinates?

What I have tried:

imageView.getTop();  

imageView.getX();

imageView.getPivotX();

Rect rect = new Rect();
imageView.getGlobalVisibleRect(rect);
rect.centerX()

Note:
ImageView is placed at the center using constraints and it is of dimension 40dp x 40dp (small image).

Abhimanyu
  • 11,351
  • 7
  • 51
  • 121
  • https://stackoverflow.com/questions/2224844/how-to-get-the-absolute-coordinates-of-a-view – keepTrackOfYourStack May 12 '19 at 13:51
  • @keepTrackOfYourStack I have already referred that question. Can you kindly specify which methods to use, if any works. – Abhimanyu May 12 '19 at 13:52
  • the second answer looks like it should work. I have used similar code. if that does not work, this might:https://stackoverflow.com/questions/53034097/how-to-get-a-views-coordinates-in-constraintlayout – keepTrackOfYourStack May 12 '19 at 14:05

0 Answers0