Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
617 views
in Technique[技术] by (71.8m points)

android - zooming image in viewflipper

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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);
    }
});

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...