【发布时间】: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 上相对于比例的位置?
请多多指教……
【问题讨论】: