在自定义视图上进行缩放无法正常工作

问题描述 投票:1回答:2

当在没有缩放的视图上绘制时,效果很好。请参阅屏幕快照“在此处输入图像描述”

但是在缩放然后在视图上绘制时,它会稍微向上或向下。查看屏幕截图

<< img src =“ https://image.soinside.com/eyJ1cmwiOiAiaHR0cHM6Ly9pLnN0YWNrLmltZ3VyLmNvbS81YzRtdy5wbmcifQ==” alt =“使用缩放”>

这是我的自定义视图http://www.paste.org/78026和缩放http://www.paste.org/78027和我的xml http://www.paste.org/78028的代码>

请您告诉我哪里错了>>

当在没有缩放的视图上绘制时,效果很好。请参阅屏幕截图,但是在缩放然后在视图上绘制时,它会稍微向上或向下。查看屏幕快照这是我的自定义视图代码http:// www ....

android canvas android-canvas pinchzoom android-bitmap
2个回答
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];

0
投票

我能知道您如何放大MainActivity吗?

© www.soinside.com 2019 - 2024. All rights reserved.