Animating Views
rutura edited this page Apr 16, 2017
·
1 revision
- we use a ViewPropertyAnimator to animate a view object.
- Call View.animate() and get a ViewPropertyAnimator object
- On it, you can call functions to animate properties like alpha ,translation, rotation...
- Quick code :
public void onClick(View v) {
if (viewToAnimate.getAlpha() > 0f) {
//If the view is visible, slide it out to the right
viewToAnimate.animate().alpha(0f).translationX(1000f);
} else {
//If the view is hidden, do a fade-in in place
//Property Animations actually modify the view, so
// we have to reset the view's location first
viewToAnimate.setTranslationX(0f);
viewToAnimate.animate().alpha(1f);
}
}