Reputation: 103
I would like to know how you detect the end of an animation. Here is the animation:
image.animate().xBy(screenWidth-200).setDuration(5000).start();
Upvotes: 2
Views: 1723
Reputation: 5312
Add an AnimatorListener
:
Animator.AnimatorListener listener = new Animator.AnimatorListener() {
@Override
public void onAnimationStart(Animator animation) {
}
@Override
public void onAnimationEnd(Animator animation) {
}
@Override
public void onAnimationCancel(Animator animation) {
}
@Override
public void onAnimationRepeat(Animator animation) {
}
});
image.animate().xBy(screenWidth-200).setDuration(5000).setListener(listener).start();
Upvotes: 3
Reputation: 2213
Are you trying to execute some action after the animation ends? If so try modifying your code like below :
image.animate()
.xBy(screenWidth-200)
.setDuration(5000)
.withEndAction(new Runnable() {
@Override
public void run() {
// Do something when animation ends
}
})
.start();
Upvotes: 1
Reputation: 2638
addListener(AnimatorListener) override method
https://developer.android.com/reference/android/animation/Animator.AnimatorListener.html
Upvotes: 0