I would like to know if it is possible to get the coordinates, left and top, of an ImageView.
I have 2 ImageView inside a RelativeLayout inside a ScrollView.
I tried to retrieve the matrix of the ImageView with matrix = _iv.getImageMatrix();
but it is not helpful Matrix{[1.0, 0.0, 0.0][0.0, 1.0, 0.0][0.0, 0.0, 1.0]}
.
Any ideas? Would it make a difference if the getImageMatix()
is run in a different place?
Asked
Active
Viewed 1,931 times
0

slybloty
- 6,346
- 6
- 49
- 70
-
you want to get co-ordinates of ImageView onClick event...? – Lalit Poptani Oct 07 '11 at 16:40
-
The event will give me the screen coordinates, which I want to correlate with the ImageView, no matter where on the screen is located. That's why I am looking for its coordinates from the screen. – slybloty Oct 07 '11 at 17:01
-
yes but you can get it on any of the event. – Lalit Poptani Oct 07 '11 at 17:03
1 Answers
1
Here's a better way to do it. I implemented an OnTouchListener in the ImageView itself and the X,Y coordinates are corresponding to the ImageView.
_iv.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
//Choose which motion action has been performed
switch(event.getAction())
{
case MotionEvent.ACTION_DOWN:
//Get X, Y coordinates from the ImageView
int X = (int) event.getX();
int Y = (int) event.getY();
//Do something
break;
case MotionEvent.ACTION_MOVE:
break;
case MotionEvent.ACTION_UP:
break;
}
return true;
}
}); //End setOnTouchListner()

slybloty
- 6,346
- 6
- 49
- 70