Android - Zooming on only Position (0,0) instead whole image

Viewed 50

I am currently working on a project and where I have added an Image class to a Linear layout as a view, now I am trying to zoom in on the Image class using the scale example from: https://developer.android.com/training/gestures/scale

I have used that example to the dot and have made no changes.

However, the scaling only works at Position (0,0) and I can not scale to other parts of the Image. Regardless where I gesture from it only zooms towards Position (0,0)

If anyone would suggest me some changes to make this work. That would be really appreciated.

1 Answers

In order to scale up/down to a different point, you must specify the pivot point coordinates.

Based on the example from training docs, you are using the canvas.scale(x,y) method. But as you can see from the Canvas class documentation, there is an overload of that method that takes the pivot coordinates as well.
So to scale to the middle for example you might use:

canvas.scale(x,y,width/2,height/2)
Related