title: Android: Resize image width and height in dip
body: <p>I am creating an app that downloads an image from a url, save them on the device and after must load them into a ImageView with a fixed size.
  For the download and the saving of the file i've no problem but when i try to set the image in the ImageView i have a fatal error, because the image is to large for my ImageView (i think...).</p>
  
  <p>this is the xml file:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="fill_parent"
  android:layout_height="wrap_content"
  android:background="#ff9f9f"
  android:layout_margin="2dip"
  android:padding="2dip"&gt;
  
  &lt;RelativeLayout
      android:layout_width="fill_parent"
      android:layout_height="wrap_content"
      android:background="#ff9f9f"
      android:layout_margin="2dip"
      android:padding="2dip"&gt;
  
      &lt;TextView
          android:id="@+id/notizieTitolo"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_toRightOf="@+id/immagineNotizie"
          android:text="Titolo"
          android:textColor="#6b71f1"
          android:textSize="20dip"
          android:layout_margin="2dip" /&gt;
  
      &lt;TextView
          android:id="@+id/notizieSottoTitolo"
          android:layout_width="fill_parent"
          android:layout_height="wrap_content"
          android:layout_below="@+id/immagineNotizie"
          android:text="SottoTitolo"
          android:textSize="15dip" 
          android:layout_margin="2dip"/&gt;
  
      &lt;ImageView
          android:background="@drawable/icona"
          android:id="@+id/immagineNotizie"
          android:layout_width="100dip"
          android:layout_height="100dip"
          android:layout_margin="2dip" /&gt;
  
  &lt;/RelativeLayout&gt;
  &lt;/ScrollView&gt;
  </code></pre>
  
  <p>Is a simple layout with a ImageView, one TextView to the right of the ImageView and a TextView under all</p>
  
  <p>The important is the ImageView with and height. Are set to 100dip (if i count the 2dip for the margin).</p>
  
  <p>this th code of the class with the image saved in a Bitmap.</p>
  
  <pre><code>public class Notizia {
      String url;
      String titolo;
      String sottoTitolo;
      String nomeImmaginSalvata;
      Bitmap immagine;
  
  public Notizia(String tit, String sottoTit, Bitmap imm, String lk){
      titolo = tit;
      sottoTitolo = sottoTit;
      immagine = imm;
      url = lk;
      nomeImmaginSalvata = nomeImmSalvata;
  }
  }
  </code></pre>
  
  <p>In this case I will use the image immediately after the download without saving it to disk, because it isn't essential to save.</p>
  
  <p>This is the code for create a dynamic layout using the xml layout</p>
  
  <pre><code>LayoutInflater layoutInflator = (LayoutInflater) getApplicationContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
          LinearLayout insertPoint = (LinearLayout) findViewById(R.id.ll_content);
          List views = new ArrayList();
  
          Iterator&lt;Notizia&gt; it = (Dati.listaNotizie).iterator();
          while (it.hasNext()){
              Notizia not = it.next();
              View view = layoutInflator.inflate(R.layout.layout_notizie, null);
              TextView textView = (TextView) view.findViewById(R.id.notizieTitolo);
              Bitmap yourBitmap = not.getImmagine();
              Bitmap resized = Bitmap.createScaledBitmap(yourBitmap, 10, 10, true);
              TextView textView1 = (TextView) view.findViewById(R.id.notizieSottoTitolo);
              ImageView img = (ImageView) findViewById(R.id.immagineNotizie);
              img.setImageBitmap(resized);
              textView.setText(not.getTitolo());
              textView1.setText(not.getSottoTitolo());
              view.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
              views.add(view);
          }
  
          for(int i = 0; i&lt;views.size(); i++)
              insertPoint.addView((View) views.get(i));
      }
  </code></pre>
  
  <p>My question is: how to resize the image width and height in 100dip (or 98)?</p>
  
  <p>I've try the</p>
  
  <pre><code>Bitmap resized = Bitmap.createScaledBitmap(yourBitmap, width, heigh, true);
  </code></pre>
  
  <p>but nothing.</p>