Or better yet, use the animation:
Animation animation = new Animation() { @Override protected void applyTransformation(float interpolatedTime, Transformation t) { LayoutParams params = view1.getLayoutParams(); params.leftMargin = (int)(50 * interpolatedTime); view1.setLayoutParams(params); } }; animation.setDuration(300); animation.setInterpolator(new OvershootInterpolator()); view1.startAnimation(animation);
Or better yet, use the helper library :
ViewPropertyObjectAnimator.animate(view1).leftMargin(50).setDuration(300).start();
source share