在缩放无法正常工作的自定义视图上绘制

Draw on custom view with zoom not working properly

在没有缩放的情况下在视图上绘图时效果很好。看截图

但是当缩放然后在视图上绘图时它会稍微向上或向下。看截图

这是我的自定义视图代码 http://www.paste.org/78026 and for zoom http://www.paste.org/78027 and my xml http://www.paste.org/78028

请你告诉我我哪里错了

经过大量搜索,我终于找到了如何在缩放视图时获取相对 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];