UPDATE 2: getX and getY will return 0 if you use an undefined width and height (e.g. wrap_content). Instead of iv.getX() and iv.getY() replace this with the answer to this question: Getting view coordinates relative to the root layout , then add image borders to these values.
You can do this by adding an ImageView position to the upper left border of the popped inside. Something like that:
ImageView iv = (ImageView)findViewById(R.id.image_view); Drawable d = iv.getDrawable(); Rect bounds = d.getBounds(); int top = iv.getY() + bounds.top; int left = iv.getX() + bounds.left;
UPDATE: for scalable images, you will need to multiply the top and left coordinates by the image scale to get a more accurate positioning. You can do it like this:
Matrix m = iv.getImageMatrix(); float[] values = new float[9]; m.getValues(values); float scaleX = values[Matrix.MSCALE_X]; float scaleY = values[Matrix.MSCALE_Y];
Then you will need to multiply the vertex by scaleY, and on the left by scaleX.
source share