在没有缩放的情况下绘制视图时,它可以正常工作。请参见屏幕截图
但是当缩放然后在视图上绘图时它会略微向上或向下。见截图
以下是自定义视图http://www.paste.org/78026和缩放http://www.paste.org/78027以及我的xml http://www.paste.org/78028
的代码请告诉我我错在哪里
答案 0 :(得分:0)
最后经过大量搜索后,我发现当View变焦时如何获得相对X,Y。这可能对某人有帮助
// Get the values of the matrix
float[] values = new float[9];
matrix.getValues(values);
// values[2] and values[5] are the x,y coordinates of the top left corner of the drawable image, regardless of the zoom factor.
// values[0] and values[4] are the zoom factors for the image's width and height respectively. If you zoom at the same factor, these should both be the same value.
// event is the touch event for MotionEvent.ACTION_UP
float relativeX = (event.getX() - values[2]) / values[0];
float relativeY = (event.getY() - values[5]) / values[4];