title: Matrix scale video on TextureView Android
body: <p>I'm trying to play video with <code>ExoPlaye</code> on <code>TextureView</code>. In order to scale and crop video to fit view I use matrix. My custom view extends `TextureView' Here is my code:</p>
  
  <pre><code>@Override
  public void onVideoSizeChanged(int width, int height, float pixelWidthHeightRatio) {
      updateTextureViewSize(width, height);
      Log.v("EXO", "onVideoSizeChanged() " +  width + "x" + height);
  }
  
  private void updateTextureViewSize(float videoWidth, float videoHeight) {
      float viewWidth = getWidth();
      float viewHeight = getHeight();
  
      float scaleX = 1.0f;
      float scaleY = 1.0f;
  
      float viewRatio = viewWidth / viewHeight;
      float videoRatio = videoWidth / videoHeight;
      if (viewRatio &gt; videoRatio) {
          // video is higher than view
          scaleY = videoHeight / videoWidth;
      } else {
          //video is wider than view
          scaleX = videoWidth / videoHeight;
      }
  
      Matrix matrix = new Matrix();
      matrix.setScale(scaleX, scaleY, viewWidth / 2, viewHeight / 2);
  
  
      setTransform(matrix);
  }
  </code></pre>
  
  <p>I had a rectangular views and it worked perfectly. But now views have 2 states: expanded (the old ones that are still rectangular) and collapsed (have smaller height.</p>
  
  <p>So now video is stretched vertically in those collapsed views. </p>
  
  <p>For instance I have view <code>1080x480</code> and video <code>360x640</code> but it looks like video is scaled and cropped to <code>1080x1080</code> and than stretched to <code>1080x480</code>.</p>
  
  <p>What am I doing wrong here ?</p>
  
  <p>UPD: Here are screenshots:
  <a href="https://i.stack.imgur.com/HkEj9.jpg" rel="noreferrer"><img src="https://i.stack.imgur.com/HkEj9.jpg" alt="enter image description here"></a></p>