Sometimes we need to animate some view in our application. Here is a sample code for translate a view over x axis from its location.
bt = (Button) findViewById(R.id.bt);
TranslateAnimation animation = new TranslateAnimation(Animation.RELATIVE_TO_SELF, 300, Animation.RELATIVE_TO_SELF, Animation.RELATIVE_TO_SELF);
But the problem of this code is if you want to click this button after animate you can not, why lets read the documentation from android developer site
disadvantage of the view animation system is that it only modified where the View was drawn, and not the actual View itself. For instance, if you animated a button to move across the screen, the button draws correctly, but the actual location where you can click the button does not change, so you have to implement your own logic to handle this.
To solve this issue we will use ObjectAnimator class to animate our view.
ObjectAnimator animXNext = ObjectAnimator.ofFloat(bt, "translationX", Animation.RELATIVE_TO_SELF, 300);
Now you can click on the button. Enjoy 🙂