2014-06-27 92 views
0

我有一个TableLayout的单元格为ImageView s。我想要做的是通过增加表格中的ImageView s的大小来创建缩放效果。这适用于缩小(图片大小调整为ImageView),但问题在于放大。图片不会在ImageView变大时调整大小。ImageView图像不调整与ImageView的大小

下面是一个例子: enter image description here

我想要的图像是尺寸为ImageView的相同(每个黑色方块是一个ImageView的)

这里是我的变焦代码(在任何提示更好的实施将不胜感激,不想使用捏缩放)。

zoomIndex ranges from -2, 2. (only allow them to zoom twice in each direction) 
zoomInThreshold = 2, zoomOutThreshold = -2. 
defaultSize = 50, zoomIncrement = 15; 


       if(zoomIndex < zoomInThreshold) 
        defaultSize += zoomIncrement; 


       for(int i = 0; i < table.getChildCount(); ++i) 
       { 
        TableRow row = (TableRow)table.getChildAt(i); 
        for(int r = 0; r < row.getChildCount(); ++r) 
        { 
         ImageView img = (ImageView)row.getChildAt(r); 

         if(zoomIndex < zoomInThreshold) 
         { 
          TableRow.LayoutParams imgLayoutParams = new TableRow.LayoutParams(
            defaultSize, 
            defaultSize 
          ); 
          img.setLayoutParams(imgLayoutParams); 

          if(img.getDrawable() != null) 
          { 
           img.setAdjustViewBounds(true); 
           img.setMaxHeight(defaultSize); 
           img.setMaxWidth(defaultSize); 
           img.setScaleType(ImageView.ScaleType.CENTER_INSIDE); 
          } 
         } 
        } 
       } 
       if(zoomIndex < zoomInThreshold) 
        zoomIndex++; 
+0

你应该为此提供赏金:) –

+0

我只能在2天内开始赏金 – john

回答

0

想通了这个问题,这个问题只发生在我从xml文件加载绘图时发生。我所要做的就是加载图纸

img.setAdjustViewBounds(true); 

时,这是它如何适应加入这一行:

   if(drawableID != -1) 
       { 
        Bitmap pic = BitmapFactory.decodeResource(getResources(), drawableID); 
        Bitmap resizedBitmap = Bitmap.createScaledBitmap(pic, 50, 50, true); 
        im.setImageBitmap(resizedBitmap); 

        ic.setImage(im); 

        im.setTag(ic); 

        im.setAdjustViewBounds(true); 

        //rotate the icon 
        im.setScaleType(ImageView.ScaleType.MATRIX); 
        Matrix matrix = new Matrix(); 
        matrix.set(im.getImageMatrix()); 
        matrix.postRotate(rotAngle, pic.getWidth()/2, pic.getHeight()/2); 
        im.setImageMatrix(matrix); 

        im.setOnLongClickListener(longListen);//only set this listener if there is something there 
       } 

我只有在我的变焦按钮按img.setAdjustViewBounds(true);

相关问题