I want to animate a button by getting its co-ordinates and then increasing or decreasing them one by one so that the button can go to left and then come to the right.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With