How to position pinch zoomable image?
I'm having trouble finding a related problem.
I currently have an ImageView contained in a ScrollView. I've implemented a zoomable bitmap using multi-touch. The problem is, ins开发者_运维问答tead of the image zooming wherever it may lay on the screen. I want the images top/left corner to always remain in the screens top/left corner.
Thanks
First of all, I've implemented zooming in the past using the techniques in this article from ZDNet.
But, as you've noted, this doesn't cover the boundary conditions. The trick is to make sure that you keep the point you want to remain fixed constant. The function below shows a snippet of a common zooming command. What you will need to do is to make sure that the matrix is centered on a point such that the center changes based off of the size of your zoom function. Good luck!
else if (mode == ZOOM) {
float newDist = spacing(event);
Log.d(TAG, "newDist=" + newDist);
if (newDist > 10f) {
matrix.set(savedMatrix);
float scale = newDist / oldDist;
matrix.postScale(scale, scale, mid.x, mid.y);
}
}
精彩评论