【问题标题】:Moving a point(xx, yy) on ImageView with respect to pinch zoom of ImageView相对于 ImageView 的捏缩放在 ImageView 上移动一个点(xx,yy)
【发布时间】:2013-12-16 07:14:14
【问题描述】:

我正在 ImageView 上绘制一个小图标(用于在其上绘制小图块),它使用缩放捏合进行缩放。我可以像这样滚动主 ImageView 时移动该图标:

public boolean onTouch(View v, MotionEvent event) {

case MotionEvent.ACTION_MOVE:
if (mode == Util.DRAG) {

//this scrolls image view       
matrix.set(savedMatrix);
matrix.postTranslate(event.getX() - start.x, event.getY() - start.y);
..
.. 
//
int xx = (int) (event.getX() - start.x);
int yy = (int) (event.getY() - start.y);
xx = (Icon.xpos + xx);
xx = (Icon.ypos + yy);
Icon.drawViewOnScreen(xx , yy);

}else if(mode == ZOOM){ //pinch zoom

float newDist = spacing(event);
if (newDist > 10f && ((newDist - oldDist) > 10f || (oldDist - newDist) > 10f)) {
matrix.set(savedMatrix);
float scale = newDist / oldDist;
matrix.getValues(matrixValues);
float currentScale = matrixValues[Matrix.MSCALE_X];
scale = .65f / currentScale;
matrix.postScale(scale, scale, Util.screenWidth / 2, Util.screenHeight / 2);

Icon.drawViewOnScreen(Icon.xpos+scale, Icon.ypos+scale); **// This gets icon away from its orignal location. I need to make it stay on same map tile which needs actually adjusting
     its position with respect to scale. I have attached a sample image to express**

}}
image.setImageMatrix(matrix);

我们应该在每次调用 pinch 时为 Icon 的 xx 和 yy 添加什么因素,以便它可以更新其在 ImageView 上相对于比例的位置?

请多多指教……

【问题讨论】:

    标签: android imageview zooming


    【解决方案1】:

    你应该使用mapPoints()

    例子:

    你有你想要移动的点的绝对坐标

    int relX=mapPoints(absolX);
    int relY=mapPoints(absolY);
    

    然后在你的onDraw中,在relXrelY上画点

    我知道答案有点晚了,抱歉

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-01-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-07-08
      • 2017-12-02
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多