title: Android image scale type to fit width and scaleY = scaleX
body: <p>I have a layout with a background image. The image width should be the same as the screen width (match_parent). But it's ugly, the OS don't stretch the picture in height.
  I heard about ImageView scaleType, so I have the background image in an ImageView instead of a layout background, but I can't config to be what I want.</p>
  
  <p><strong>How can I set to the layout or ImageView to scale the image (in width) to fit the width of the screen AND scale the height with the same scale?</strong></p>
  
  <p>I want the second screen in the picture:
  <img src="https://i.stack.imgur.com/50not.jpg" alt="enter image description here"></p>
  
  <p>UPDATE:</p>
  
  <p>I'm trying from code, but I get 0 width + I can't believe this can't be done from xml with an ImageView. </p>
  
  <pre><code>    Drawable imageDrawable = getResources().getDrawable(imageResource);
      contentContainer.setBackgroundDrawable(imageDrawable);
  
      Rect rect = imageDrawable.getBounds();
      int originalWidth = rect.width();
      int originalHeight = rect.height();
  
      Display display = getActivity().getWindowManager().getDefaultDisplay(); 
      int width = display.getWidth();
  
      int height = originalHeight * (width/originalWidth);
  
      RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(width, height);
      contentContainer.setLayoutParams(layoutParams);
  
  
      contentContainer.post(new Runnable() {
  
          @Override
          public void run() {
              contentContainer.setScaleY(contentContainer.getScaleX());
  
              Rect rect = contentContainer.getBackground().getBounds();
              int originalWidth = rect.width();
              int originalHeight = rect.height();
  
              Display display = getActivity().getWindowManager().getDefaultDisplay(); 
              int width = display.getWidth();
  
              int height = originalHeight * (width/originalWidth);
  
              RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(width, height);
              contentContainer.setLayoutParams(layoutParams);
  
          }
      }
  </code></pre>