title: Scale an image up to fill entire ImageView in Android
body: <p>I'd like to scale an image up to take up the entire size of an ImageView.  This is subtly different than using <code>scaleType=fit_center</code> because <a href="http://developer.android.com/intl/fr/reference/android/graphics/Matrix.ScaleToFit.html#CENTER" rel="noreferrer">fit_center</a> will leave bands around the image if the image aspect ratio does not exactly match the ImageView's aspect ratio.  Instead, I would like the image to get centered and scaled up to completely fill the enclosing view, with any excess chopped off.</p>
  
  <p>I'm able to accomplish this by computing my own custom image matrix during onCreate():</p>
  
  <pre><code>final Display display = getWindowManager().getDefaultDisplay();
  final float screenWidth = display.getWidth();
  final float screenHeight = display.getHeight();
  final float imageWidth = splashView.getDrawable().getIntrinsicWidth();
  final float imageHeight = splashView.getDrawable().getIntrinsicHeight();
  final Matrix splashMatrix = new Matrix();
  final float scale = Math.max(screenHeight/imageHeight,screenWidth/imageWidth);
  splashMatrix.postScale( scale, scale );
  splashView.setImageMatrix(splashMatrix);
  </code></pre>
  
  <p>This works fine, but it seems like there must be  an easier away.  Does anyone know of a way to scale up an image in an ImageView while both preserving the aspect ratio of the image and fully filling in the ImageView?</p>
  
  <p>(Note: in my case my ImageView is taking up the full screen, so I use <code>getWindowManager().getDisplay()</code> to find the desired image size.  You can't use <code>splashView.getWidth()</code>/<code>getHeight()</code> because the view hasn't been laid out yet and doesn't have a size)</p>