title: Animate button move and set new position in Android
body: <p>I've an ImageButton that I want to move when pressed and when animation finish I want that this button stops in the new position.</p>
  
  <p>This is button code:</p>
  
  <pre><code>&lt;ImageButton
      android:id="@+id/move_button"
      android:layout_width="120dp"
      android:layout_height="35dp"
      android:layout_centerInParent="true"
      android:layout_alignParentTop="true"
      android:layout_marginTop="0dp"
      android:scaleType="fitCenter"
      android:background="@drawable/background_button"
      android:src="@drawable/move_button"
      android:onClick="MoveButton" /&gt;
  </code></pre>
  
  <p>I've found a code to do that in this site:</p>
  
  <pre><code>public void MoveButton(final View view) {    
          TranslateAnimation anim = new TranslateAnimation(0, 0, 100, 0);
          anim.setDuration(300);
  
          anim.setAnimationListener(new TranslateAnimation.AnimationListener() {
  
              @Override
              public void onAnimationStart(Animation animation) { }
  
              @Override
              public void onAnimationRepeat(Animation animation) { }
  
              @Override
              public void onAnimationEnd(Animation animation)
              {
                  FrameLayout.LayoutParams params = (FrameLayout.LayoutParams)view.getLayoutParams();
                  params.topMargin += -100;
                  view.setLayoutParams(params);
              }
          });
  
          view.startAnimation(anim);
  
      }
  </code></pre>
  
  <p>When button it's pressed it start the animation, but when animation is complete button return to initial position and application crashes.</p>
  
  <p>What can be the problem?</p>