0

There is a layout like on the picture. I want to know the real coordinates of the headshape image. ImageView that contains this headshape image has 40dp margin for each side and the source image is scaled proportionally.

enter image description here

How can I get the top and bottom coordinates of the headshape?

bvk256
  • 1,837
  • 3
  • 20
  • 38

2 Answers2

0

If you want to get bounds (coordinates of corners of your image), you could go with this code:

Rect rectCoordinates = headShapeImageView.getDrawable().getBounds();

With returned Rect you can get all sorts of data about dimensions of your view, including coordinates of it's 4 corners. Refer to docs here: https://developer.android.com/reference/android/graphics/Rect.html

However, if you want to get imageView resolution instead of bounds, refer to an answer here: Get the displayed size of an image inside an ImageView

Cheers!

Community
  • 1
  • 1
0

I solved my problem by calculating the ratio of height-to-width of original image. And if the width is known then we can calculate the top and bottom, knowing the center.

bvk256
  • 1,837
  • 3
  • 20
  • 38