Я использую Kotlin, но в Java это будет выглядеть так же
val animatorSet = AnimatorSet()
val positionAnimator = ValueAnimator.ofFloat(tv.x, 0F)
positionAnimator.duration = animationDuration
positionAnimator.addUpdateListener {
tv.x = positionAnimator.animatedValue as Float
}
val alphaAnimation = ValueAnimator.ofFloat(1F, 0F, 1F)
alphaAnimation.duration = animationDuration
alphaAnimation.addUpdateListener {
tv.alpha = alphaAnimation.animatedValue as Float
}
animatorSet.addListener(object : AnimatorListenerAdapter() {
override fun onAnimationEnd(animation: Animator) {
super.onAnimationEnd(animation)
//If you need some events
}
})
positionAnimator.interpolator = AccelerateDecelerateInterpolator()
animatorSet.playTogether(positionAnimator, alphaAnimation)
animatorSet.start()
Для JAVA.Это всего лишь пример.
private void animate() {
animatorSet = new AnimatorSet();
ValueAnimator positionAnimator = ValueAnimator.ofFloat(0, 100F);
positionAnimator.setDuration(200);
positionAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator valueAnimator) {
view.setX((Float) valueAnimator.getAnimatedValue());
}
});
ValueAnimator alphaAnimation = ValueAnimator.ofFloat(0f, 1F);
positionAnimator.setDuration(200);
positionAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator valueAnimator) {
view.setAlpha((Float) valueAnimator.getAnimatedValue());
}
});
animatorSet.addListener(new Animator.AnimatorListener() {
@Override
public void onAnimationStart(Animator animation, boolean isReverse) {
}
@Override
public void onAnimationEnd(Animator animation, boolean isReverse) {
}
@Override
public void onAnimationStart(Animator animator) {
}
@Override
public void onAnimationEnd(Animator animator) {
}
@Override
public void onAnimationCancel(Animator animator) {
}
@Override
public void onAnimationRepeat(Animator animator) {
}
});
positionAnimator.setInterpolator(new AccelerateDecelerateInterpolator());
animatorSet.playTogether(positionAnimator, alphaAnimation);
animatorSet.start();
}