【问题标题】:Draw on custom view with zoom not working properly在缩放无法正常工作的自定义视图上绘制
【发布时间】:2023-03-27 07:56:01
【问题描述】:

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

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

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

请你告诉我哪里错了

【问题讨论】:

  • 您的上述问题解决了吗?
  • @Jiks 是的,已经解决了

标签: android canvas android-canvas pinchzoom android-bitmap


【解决方案1】:

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

【讨论】:

  • 您好!您能否在这一行中解释更多关于矩阵的信息 matrix.getValues(values); ?这是什么?
猜你喜欢
  • 1970-01-01
  • 2013-04-17
  • 1970-01-01
  • 2019-10-24
  • 1970-01-01
  • 1970-01-01
  • 2022-01-20
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多