How to chain animation in android to the same view?
You probably mean AnimatorSet (not AnimationSet). As written in documentation:
This class plays a set of
Animator
objects in the specified order. Animations can be set up to play together, in sequence, or after a specified delay.There are two different approaches to adding animations to a AnimatorSet: either the
playTogether()
orplaySequentially()
methods can be called to add a set of animations all at once, or theplay(Animator)
can be used in conjunction with methods in theBuilder
class to add animations one by one.
Animation which moves view
by -100px
for 700ms
and then disappears during 300ms
:
final View view = findViewById(R.id.my_view);
final Animator translationAnimator = ObjectAnimator
.ofFloat(view, View.TRANSLATION_Y, 0f, -100f)
.setDuration(700);
final Animator alphaAnimator = ObjectAnimator
.ofFloat(view, View.ALPHA, 1f, 0f)
.setDuration(300);
final AnimatorSet animatorSet = new AnimatorSet();
animatorSet.playSequentially(
translationAnimator,
alphaAnimator
);
animatorSet.start()