相对于ImageView的缩放缩放,在ImageView上移动一个点(xx,yy)

时间:2013-12-16 07:14:14

标签: android imageview zoom

我在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);

enter image description here 我们应该在每次调用时添加到图标的xx和yy,以便它可以在比例尺上更新其在ImageView上的位置?

请注意......

1 个答案:

答案 0 :(得分:1)

您应该使用mapPoints()

示例:

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

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

然后在你的onDraw中,在relXrelY

上绘制点

我知道答案有点晚了,sry