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?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答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()