title: creating a scaled bitmap in onCreate() according to the Imageviews height and width
body: <p>Here is the problem im having, in the onCreate() i would like to initially set the imageview to the first image in the list of files but with the ImageViews width and height, when it flips back and forth it sets the image to the ImageViews dimentions no problem but in the onCreate() i get IllegalArgumentException width and height must be greater than 0. i tried to make the start method if as it wasnt happening in the onCreate(), idk, any help is greatly appreciated, thank you for your time</p>
  
  <pre><code>    public class ViewFlipperActivity extends Activity {
  
     ViewFlipper page;
  
     Animation animFlipInForeward;
     Animation animFlipOutForeward;
     Animation animFlipInBackward;
     Animation animFlipOutBackward;
     String[] imagefiles;
     File file = new File(Environment.getExternalStoragePublicDirectory(
                Environment.DIRECTORY_PICTURES), "how");
     int filescount,nowcount;
     ImageView image;
     Matrix matrix;
     Bitmap d;
  
     /** Called when the activity is first created. */
     @Override
     public void onCreate(Bundle savedInstanceState) {
     super.onCreate(savedInstanceState);
     setContentView(R.layout.main);
     imagefiles = file.list();
     filescount = imagefiles.length;
     nowcount = 0;
     matrix = new Matrix();
     matrix.postRotate(90);
     page = (ViewFlipper)findViewById(R.id.flipper);
     image = (ImageView)findViewById(R.id.zero);
  
     animFlipInForeward = AnimationUtils.loadAnimation(this, R.anim.left_in);
     animFlipOutForeward = AnimationUtils.loadAnimation(this, R.anim.left_out);
     animFlipInBackward = AnimationUtils.loadAnimation(this, R.anim.right_in);
     animFlipOutBackward = AnimationUtils.loadAnimation(this, R.anim.right_out);
     start();
     }
     private void start(){
     d = BitmapFactory.decodeFile(file.toString() +"/" + imagefiles[nowcount]);
  
     d = Bitmap.createBitmap(d, 0, 0, d.getWidth(), d.getHeight(), matrix, true);
     System.gc();
     d = Bitmap.createScaledBitmap(d, image.getWidth(), image.getHeight(), true);
     System.gc();
     image.setImageBitmap(d);
     System.gc();
     }
  
     private void SwipeRight(){
     page.setInAnimation(animFlipInBackward);
     page.setOutAnimation(animFlipOutBackward);
     nowcount--;
     if(nowcount &lt; 0)
   nowcount = filescount - 1;
     d = BitmapFactory.decodeFile(file.toString() +"/" + imagefiles[nowcount]);
  
     d = Bitmap.createBitmap(d, 0, 0, d.getWidth(), d.getHeight(), matrix, true);
     System.gc();
     d = Bitmap.createScaledBitmap(d, image.getWidth(), image.getHeight(), true);
     System.gc();
     image.setImageBitmap(d);
     System.gc();
  
     page.showPrevious();
     Log.d("show previous", "exe");
     }
  
     private void SwipeLeft(){
     page.setInAnimation(animFlipInForeward);
     page.setOutAnimation(animFlipOutForeward);
     nowcount++;
     if(nowcount &gt; 3)
   nowcount = 0;
     d = BitmapFactory.decodeFile(file.toString() +"/" + imagefiles[nowcount]);
  
     d = Bitmap.createBitmap(d, 0, 0, d.getWidth(), d.getHeight(), matrix, true);
     System.gc();
     d = Bitmap.createScaledBitmap(d, image.getWidth(), image.getHeight(), true);
     System.gc();
     image.setImageBitmap(d);
     System.gc();
     page.showNext();
     Log.d("show next", "exe");
     }
  
    @Override
    public boolean onTouchEvent(MotionEvent event) {
     // TODO Auto-generated method stub
    return gestureDetector.onTouchEvent(event);
    }
  
    SimpleOnGestureListener simpleOnGestureListener
    = new SimpleOnGestureListener(){
  
    @Override
     public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,
    float velocityY) {
  
    float sensitvity = 50;
    if((e1.getX() - e2.getX()) &gt; sensitvity){
     SwipeLeft();
    }else if((e2.getX() - e1.getX()) &gt; sensitvity){
    SwipeRight();
    }
  
    return true;
    }
  
    };
  
    GestureDetector gestureDetector
    = new GestureDetector(simpleOnGestureListener);
    }
  </code></pre>