Android Gallery with pinch zoom

2019-01-13 14:31发布

问题:

I found a sample project of gallery with pinch zoom and made some bug fix. You can download my code at here

It supports full screen only. It always center the image to screen height. But I want to put a header view to the top of the screen and make the adjustment to the location of the image. The image location should be:

header height + (screen height - header height) / 2

I am not so good at using Matrix. Anyone has idea of how to make the customized gallery to work in any size (not just full screen)?

回答1:

You can use my Pinch to zoom Gallery project. You can choose any image from gallery and then in onDoubleTap(MotionEvent e) open full image and zoom it.



回答2:

You can do Image Zoom pinch option for gallery also by using below code lines:

case MotionEvent.ACTION_POINTER_DOWN:
    oldDist = spacing(event);
    Log.d(TAG, "oldDist=" + oldDist);
    if (oldDist > 10f) {
        savedMatrix.set(matrix);
        midPoint(mid, event);
        mode = ZOOM;
        Log.d(TAG, "mode=ZOOM" );
    }
    break;

Or you can download the example.