2014-04-23 140 views
0

我试图缩放显示在textview中的图像,但我不能。使用ImageGetter在textview中缩放图像

我正在使用此代码,但无论如何,它显示图像在容器内裁剪或根本不显示。

int width, height; 
DisplayMetrics metrics = new DisplayMetrics(); 
metrics = Resources.getSystem().getDisplayMetrics(); 

int originalWidthScaled = (int) (result.getIntrinsicWidth() * metrics.density); 
      int originalHeightScaled = (int) (result.getIntrinsicHeight() * metrics.density); 
      if (originalWidthScaled > metrics.widthPixels) { 
       height = result.getIntrinsicHeight() * metrics.widthPixels 
         /result.getIntrinsicWidth(); 
       width = metrics.widthPixels; 
      } else { 
       height = originalHeightScaled; 
       width = originalWidthScaled; 
      } 
       urlDrawable.drawable = result; 

       urlDrawable.setBounds(0, 0, 0+width, 0+height); 

       // change the reference of the current drawable to the result 
       // from the HTTP call 

       // redraw the image by invalidating the container 

       container.invalidate(); 

       // For ICS 
       container.setHeight(
         container.getHeight() + 
         result.getIntrinsicHeight()); 

       // Pre ICS 
       container.setEllipsize(null); 

回答

1

我回答自己,我已经改变了

if (originalWidthScaled > metrics.widthPixels) { 
       height = result.getIntrinsicHeight() * metrics.widthPixels 
         /result.getIntrinsicWidth(); 
       width = metrics.widthPixels; 
      } 

if (originalWidthScaled > (metrics.widthPixels * 70)/100) { 
       width = (metrics.widthPixels * 70)/100; 

       height = result.getIntrinsicHeight() * width 
         /result.getIntrinsicWidth(); 
      } 

现在它占据了屏幕的空间的70%,这是完全的最大大小货柜