zooming image in viewflipper
Asked Answered
W

1

1

I have created a image slideshow using ViewFlipper. I have used imageFrame.setOnTouchListener(gestureListener); to listen user touch events like single tap,long tap

But now i want to zoom in/out on current image in slideshow (ViewFlipper) ,on doubletap by user.I have searched internet for this but wasn't able to find a solution.Please help me out.

Wright answered 23/3, 2012 at 21:49 Comment(2)
Which part is giving you trouble - detecting the doubletap or zooming the View?Manda
zooming the view.Its basically is user is viewing slideshow and if image he is viewing wanted to be zoomed he can be able to do so by doubletapping on that image in running slideshowWright
M
2

There are a number of ways you can do this, but a simple way is to use the platform's ZoomControls widget, which is a simple widget consisting of a +/- button. You can attach onZoomInClickListener and an onZoomOutClickListener to handle touches to the ZoomControls widget.

In your handler, you can scale your image. Here's some sample code that uses a ScaleAnimation to do the zooming:

iv = (ImageView) findViewById(R.id.imageview);
zc = (ZoomControls) findViewById(R.id.zoom_controls);
zc.setOnZoomInClickListener(new OnClickListener() {
    public void onClick(View v) {
        float oldZoom = currentZoom;
        currentZoom = currentZoom * 1.25;
        zc.setIsZoomOutEnabled(true);
        if (3.0 < currentZoom) {
            zc.setIsZoomInEnabled(false);
        }
        scaleAnim = new ScaleAnimation(oldZoom, currentZoom, oldZoom, currentZoom, 0, 0);
        scaleAnim.setFillAfter(true);
        iv.startAnimation(scaleAnim);
    }
});
zc.setOnZoomOutClickListener(new OnClickListener() {
    public void onClick(View v) {
        float oldZoom = currentZoom;
        currentZoom = currentZoom / 1.25;
        zc.setIsZoomInEnabled(true);
        if (0.33 > currentZoom) {
            zc.setIsZoomOutEnabled(false);
        }
        scaleAnim = new ScaleAnimation(oldZoom, currentZoom, oldZoom, currentZoom, 0, 0);
        scaleAnim.setFillAfter(true);
        iv.startAnimation(scaleAnim);
    }
});
Manda answered 26/3, 2012 at 15:42 Comment(1)
You are putting the View in ViewFlipper, so you ought to have a reference to it somewhere.Manda

© 2022 - 2024 — McMap. All rights reserved.