title: Make a drawable in Android created programmatically fits parent's width and has proportional height
body: <p>So I am loading images from URLs with this method</p>
  
  <pre><code>public Drawable loadImage(String url) {
      try {
          InputStream is = (InputStream) new URL(url).getContent();
          Drawable d = Drawable.createFromStream(is, "src name");
          return d;
      } catch (Exception e) {
          System.out.println(e.getMessage()+" oh noo ");
          return null;
      }
  }
  </code></pre>
  
  <p>But I want the image's width to be the same as its parent (that is the root element with height and width 100%). I couldn't find a way to do it using only XML. It always leaves paddings on the edges. And I found out it is because the image doesn't have the same ratio of the screen. screen is, for example 16:9 and image is 4:3. Android will make paddings to fill this difference.</p>
  
  <p><strong>Do you know how can I do it programmatically when I load the image? And I need this image to remain as big as the screen's width even when the device rotates (so I think I will need to calculate it gain)</strong></p>
  
  <p>I am using this code to get the size of the screen</p>
  
  <pre><code>public Size getScreenSize(){
      Size screenSize = new Size();
  
      DisplayMetrics metrics = new DisplayMetrics();
      this.activity.getWindowManager().getDefaultDisplay().getMetrics(metrics);
  
      screenSize.height = metrics.heightPixels;
      screenSize.width = metrics.widthPixels;
  
      return screenSize;
  }
  
  public class Size{
      public double height;
      public double width;
  }
  </code></pre>
  
  <p>@EDIT1</p>
  
  <p>This is how I insert the drawable in the View. The view is already declared in the activity's XML</p>
  
  <pre><code>ImageView picture = (ImageView) findViewById(R.id.picture);
  
  picture.setImageDrawable(loadImage(url));
  </code></pre>
  
  <p>@EDIT2 </p>
  
  <p>this is how I wrote the activity layout and its style</p>
  
  <pre><code>&lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:tools="http://schemas.android.com/tools"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:orientation="vertical"
      tools:context=".MainActivity" &gt;
  
      &lt;!-- style="@style/globalHeader" --&gt;
      &lt;LinearLayout
          style="@style/globalHeader"  
          &gt;
  
          &lt;TextView
              android:id="@+id/name"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:textColor="#fff"
              android:textSize="18sp"
              android:textStyle="bold"        
              /&gt;
  
          &lt;TextView
              android:id="@+id/subtitle"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:textColor="#fff"
              android:textSize="14sp"
              /&gt;
  
      &lt;/LinearLayout&gt;
  
      &lt;ImageView
          android:layout_width="match_parent"
          android:layout_height="match_parent"
              android:id="@+id/picture"
          android:adjustViewBounds="true"
              android:scaleType="centerCrop"
          android:background="#f00"
          &gt;
      &lt;/ImageView&gt;
  
      &lt;TextView
          android:id="@+id/desc"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:padding="20dp"
          /&gt;
  
      &lt;TextView
          android:id="@+id/details"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          /&gt;
  
  &lt;/LinearLayout&gt;
  </code></pre>
  
  <p>This is the appearance I want to achieve</p>
  
  <p><a href="https://docs.google.com/a/uniriotec.br/file/d/0B2abPynX9PhkODhRVEkwcUphY28/edit?pli=1" rel="nofollow">https://docs.google.com/a/uniriotec.br/file/d/0B2abPynX9PhkODhRVEkwcUphY28/edit?pli=1</a></p>