how to move a button to left or right programmatically in android

Use a TranslateAnimation:

TranslateAnimation animation = new TranslateAnimation(start_x, start_y, end_x, end_y);
animation.setDuration(1000); // duartion in ms
animation.setFillAfter(false);
button.startAnimation(animation);

I'm not sure how you can get it's position, button.getTop() and button.getLeft() could work...


Not sure if this will help you but i was struck with the same problem i was able to do this using these methods, setTranslationX(float) setTranslationY(float)

you can use it Like this

Button button = (button) findViewById(your id); 
button.setTranslationX(a float value);

here's the android documentation that provide more information http://developer.android.com/reference/android/view/View.html#attr_android:translationX

Tags:

Android