title: how to scale image view in a loop Android
body: <p>I Want to scale my image view in a loop.
  my code is</p>
  
  <pre><code>     final ImageView view1 = (ImageView) findViewById(R.id.test1);
      Thread timer = new Thread(){
          public void run(){
              long longTime = 100;
              long shortTime = 20;
              for (int x = 0; x &lt; 2000000; x=x+10)
              {
                  scaleImage( view1, i);
                  try {
                      Thread.sleep(longTime);
                  } catch (InterruptedException e) {
                      // TODO Auto-generated catch block
                      e.printStackTrace();
                  }
  
                  try {
                      Thread.sleep(shortTime);
                  } catch (InterruptedException e) {
                      // TODO Auto-generated catch block
                      e.printStackTrace();
                  }
              }
          }
      };
  
      timer.start();
  </code></pre>
  
  <p>and the scale imgae function is</p>
  
  <pre><code>private void scaleImage(ImageView view, int boundBoxInDp)
  {
      // Get the ImageView and its bitmap
      Drawable drawing = view.getDrawable();
      Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.zero);
  
      // Get current dimensions
      int width = bitmap.getWidth();
      int height = bitmap.getHeight();
      float xScale = ((float) boundBoxInDp) / width;
      float yScale = ((float) boundBoxInDp) / height;
      float scale = (xScale &lt;= yScale) ? xScale : yScale;
      Matrix matrix = new Matrix();
      matrix.postScale(scale, scale);
  
      // Create a new bitmap and convert it to a format understood by the ImageView
      Bitmap scaledBitmap = Bitmap.createBitmap(bitmap, 0, 0, width, height, matrix, true);
      BitmapDrawable result = new BitmapDrawable(scaledBitmap);
      width = scaledBitmap.getWidth();
      height = scaledBitmap.getHeight();
  
      // Apply the scaled bitmap
  
      // Now change ImageView's dimensions to match the scaled image
      LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) view.getLayoutParams();
      params.width = width;
      params.height = height;
      view.setLayoutParams(params);
  }
  
  private int dpToPx(int dp)
  {
      float density = getApplicationContext().getResources().getDisplayMetrics().density;
      return Math.round((float)dp * density);
  }
  </code></pre>
  
  <p>but i am getting the Exception 
  when i use this code with out loop its work fine for only one function call but on multiple function call like in loop it gives me exception
  please help  ??</p>