2011-06-13 63 views
2

我有一個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; 
    } 

它並不平坦所有工作。我搜索了很多,但無法找到DoubleTap的任何工作解決方案。有任何想法嗎?

回答

5

這裏是一個很好的鏈接上雙擊imageZoom ... http://blog.sephiroth.it/2011/04/04/imageview-zoom-and-scroll/

+0

感謝。這正是我所需要的,但不幸的是我的應用程序是2.1,而實現那裏依賴於2.2(ScaleGestureDetector)。這讓我難過。 – Sver 2011-06-13 10:51:02

+0

最後我決定堅持2.2。 – Sver 2011-06-15 09:13:32

+0

不錯.. 2.1已過時。 2.2在當前分配中佔有64.6%的份額... http://developer.android.com/resources/dashboard/platform-versions.html – Sujit 2011-06-15 09:21:14