Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/218.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 相对于ImageView的收缩缩放移动ImageView上的点(xx,yy)_Android_Imageview_Zooming - Fatal编程技术网

Android 相对于ImageView的收缩缩放移动ImageView上的点(xx,yy)

Android 相对于ImageView的收缩缩放移动ImageView上的点(xx,yy),android,imageview,zooming,Android,Imageview,Zooming,我正在ImageView上绘制一个小图标(用于在其上绘制小瓷砖),它使用缩放收缩进行缩放。我可以在滚动主图像视图时移动该图标,如下所示: public boolean onTouch(View v, MotionEvent event) { case MotionEvent.ACTION_MOVE: if (mode == Util.DRAG) { //this scrolls image view matrix.set(savedMatrix); matrix.postTra

我正在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时,我们应该向图标的xx和yy添加什么因素,以便它可以更新其在ImageView上相对于比例的位置


请思考…

您应该使用
mapPoints()

例如:

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

int relX=mapPoints(absolX);
int relY=mapPoints(absolY);
然后在onDraw中,在
relX
relY

我知道答案有点晚了,sry