title: Android: Placing a view off screen
body: <p>So I'm trying to position a view off screen, and have it I (through a translateAnimation) slide across the screen. I have it working for sliding in from the top and from the left side. But for some reason, sliding in from the right or the bottom isn't working for me. Here are the code snippets: </p>
  
  <pre><code>   final ImageView animatedSquare = new ImageView(this);
  
      //Creates a random number to choose color
      Random rand = new Random();
      //0 = Red, 1 = blue, 2 = green, 3 = gray
      int whichColor = rand.nextInt(4);
  
  
  
      //sets animatedSquare to the right color
      switch (whichColor) {
          case 0:
              animatedSquare.setImageResource(R.drawable.redsquare);
              break;
          case 1:
              animatedSquare.setImageResource(R.drawable.bluesquare);
              break;
          case 2:
              animatedSquare.setImageResource(R.drawable.greensquare);
              break;
          case 3:
              animatedSquare.setImageResource(R.drawable.graysquare);
              break;
      }
  
      final int animatedSquareSize = 150;
  
  
      RelativeLayout rl = (RelativeLayout) findViewById(R.id.homeScreen);
      RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(animatedSquareSize, animatedSquareSize);
  
      //Chooses which side of the screen to come from
      //0 = top, 1 = right, 2 = bottom, 3 = left
      int whichSide = rand.nextInt(4);
  
      //Gets width and height of screen
      Display display = getWindowManager().getDefaultDisplay();
      Point size = new Point();
      display.getSize(size);
      int width = size.x;
      int height = size.y;
  
      switch (whichSide){
          case 0: {
              int xPos = rand.nextInt(width);
              params.leftMargin = xPos;
              params.topMargin = -animatedSquareSize;
              rl.addView(animatedSquare, params);
  
              TranslateAnimation squareAnimationTop = new TranslateAnimation(0, rand.nextInt(width * 2) - (float)(0.5 * width), 0, height + animatedSquareSize);
              squareAnimationTop.setDuration(5000);
              squareAnimationTop.setFillEnabled(true);
              squareAnimationTop.setFillBefore(true);
              animatedSquare.startAnimation(squareAnimationTop);
          }
  
  
              break;
          case 1: {
              int yPos = rand.nextInt(height);
              params.leftMargin = width;
              params.topMargin = yPos;
              rl.addView(animatedSquare, params);
  
              TranslateAnimation squareAnimationRight = new TranslateAnimation(0, -(width + animatedSquareSize), 0, rand.nextInt(height) - yPos);
              squareAnimationRight.setDuration(5000);
              squareAnimationRight.setFillEnabled(true);
              squareAnimationRight.setFillBefore(true);
              animatedSquare.startAnimation(squareAnimationRight);
          }
              break;
          case 2: {
              int xPos = rand.nextInt(width);
              params.leftMargin = xPos;
              params.topMargin = height;
              rl.addView(animatedSquare, params);
  
              TranslateAnimation squareAnimationTop = new TranslateAnimation(0, rand.nextInt(width * 2) - (float)(width * 0.5), 0, -(height + animatedSquareSize));
              squareAnimationTop.setDuration(5000);
              squareAnimationTop.setFillEnabled(true);
              squareAnimationTop.setFillBefore(true);
              animatedSquare.startAnimation(squareAnimationTop);
          }
              break;
          case 3:{
              int yPos = rand.nextInt(height);
              params.leftMargin = -animatedSquareSize;
              params.topMargin = yPos;
              rl.addView(animatedSquare, params);
  
              TranslateAnimation squareAnimationRight = new TranslateAnimation(0, width + animatedSquareSize, 0, rand.nextInt(height * 2) - (float)(0.5 * height));
              squareAnimationRight.setDuration(5000);
              squareAnimationRight.setFillEnabled(true);
              squareAnimationRight.setFillBefore(true);
              animatedSquare.startAnimation(squareAnimationRight);
          }
              break;
      }
  </code></pre>
  
  <p>Like I said, Case 0 and Case 3 work perfectly. But for some reason when case 1 or 2 execute, nothing happens.</p>
  
  <p>Additionally, if I do something like this:</p>
  
  <pre><code>  case 1: {
              int yPos = rand.nextInt(height);
              params.leftMargin = width - 20; //I changed this line- subtracted 20
              params.topMargin = yPos;
              rl.addView(animatedSquare, params);
  
              TranslateAnimation squareAnimationRight = new TranslateAnimation(0, -(width + animatedSquareSize), 0, rand.nextInt(height) - yPos);
              squareAnimationRight.setDuration(5000);
              squareAnimationRight.setFillEnabled(true);
              squareAnimationRight.setFillBefore(true);
              animatedSquare.startAnimation(squareAnimationRight);
          }
  </code></pre>
  
  <p>It resizes the image to be 20dp large, and then completes the translation. It's as if I can't place anything off the screen to the right or below.</p>
  
  <p>Any help would be appreciated thanks!</p>