Reputation: 200
I am drawing a small icon on ImageView(used to draw small tiles on it) which uses zoom pinch for zoom. I can move that icon when scrolling main ImageView like this:
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);
What factor should we add to xx and yy of Icon on each call to pinch so that it could update its position on ImageView with respect to scale?
Thoughts please...
Upvotes: 1
Views: 452
Reputation: 738
You should use mapPoints()
Example:
you have the absolutes coordinates of the point you want move
int relX=mapPoints(absolX);
int relY=mapPoints(absolY);
then in you onDraw, draw the points on relX
and relY
I know the answer go a bit late, sry
Upvotes: 1