平滑图像缩放双击

时间:2011-06-13 07:56:41

标签: android imageview zoom

我有一个想要在双击时平滑放大的ImageView。

目前我有像这样的缩放工作

        public boolean onDoubleTap(MotionEvent e) {
        ImageView imageView = (ImageView) findViewById(imageViewId);
         int width = imageView.getWidth();
         int height = imageView.getWidth();
         float maxScale;
         if ( width < height ) {
         maxScale = (float) (width * Math.pow(1.5, 6));
         } else {
         maxScale = (float) (height * Math.pow(1.5, 6));
         }

         Drawable d = imageView.getDrawable();
         int imageWidth = d.getIntrinsicWidth();
         int imageHeight = d.getIntrinsicHeight();
         float[] value = new float[9];
         matrix.getValues(value);
         scaleWidth = (int)(imageWidth * value[Matrix.MSCALE_X]);
         scaleHeight = (int)(imageHeight * value[Matrix.MSCALE_Y]);

         if ( (scaleWidth * 2) < maxScale ) {
         matrix.postScale(2, 2, e.getRawX(), e.getRawY());
         } else {
         matrix.postScale(0, 0, e.getRawX(), e.getRawY());
         }
         isDoubleTab = true;
         tuneMatrix(matrix);
         savedMatrix.set(matrix);
        return false;
    }

一点也不顺利。我google了很多,但无法为DoubleTap找到任何有用的解决方案。有什么想法吗?

1 个答案:

答案 0 :(得分:5)

这是双击图像缩放的一个很好的链接... http://blog.sephiroth.it/2011/04/04/imageview-zoom-and-scroll/