zooming image in viewflipper

青春壹個敷衍的年華 提交于 2019-11-29 08:48:45

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);
    }
});
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!