我仍然不知道为什么
getX(),
getY(),
setX(),并
setY()不能代表查看的屏幕上的位置,但我想通了,如何让屏幕上的视图对象的实际位置:
getLocationOnScreen(coordinates)。
coordinates2位置int数组(
int [2] )在哪里。
例如,要获取对应于ImageView左上角的实际值,
image我只需要执行以下操作:
int[] img_coordinates = new int[2];ImageView image = (ImageView) findViewById(R.id.myImage);image.getLocationOnScreen(img_coordinates);
然后,我实际上可以将这些坐标与Touch-event的
getRawX和进行比较
getRawY。
如果我想获得视图的中心点,我只需要这样做:
x_center = (double)img_coordinates[0] + image.getWidth()/2.0;y_center = (double)img_coordinates[1] + image.getHeight()/2.0;
我希望这也会对其他人有所帮助,我花了一段时间找到了这种方法,实际上我不确定这是否是最好的方法,但是它对我有用。



