我为文本视图制作了一个动画(ObjectAnimator),它可以正常工作,但是我有一个问题。 我想知道动画持续时间结束后是否可以立即使用任何方法? (我的意思是当我们使用CountDownTimer时使用类似onFinish的方法) 我想要动画完成后在应用程序中运行的其余方法和代码。是否有解决方案?
ObjectAnimator deltaXAnimation = ObjectAnimator.ofFloat(winMassage,"scaleX",1f,1.5f);
deltaXAnimation.setDuration(300);
deltaXAnimation.start();
ObjectAnimator deltaYAnimation = ObjectAnimator.ofFloat(winMassage,"scaleY",1f,1.5f);
deltaYAnimation.setDuration(300);
deltaYAnimation.start();
答案 0 :(得分:0)
下面的代码可能很容易理解,为ObjectAnimator创建了一个侦听器
ObjectAnimator deltaXAnimation =
ObjectAnimator.ofFloat(winMassage,"scaleX",1f,1.5f);
deltaXAnimation.setDuration(300);
deltaXAnimation.start();
anim.setAnimationListener(new Animation.AnimationListener() {
public void onAnimationStart(Animation a) {
//
}
public void onAnimationRepeat(Animation a) {
}
public void onAnimationEnd(Animation a) {
}
});
我们也可以转到您的ObjectAnimator
Handler handler = new Handler();
handler.postDelayed(new Runnable() {
@Override
public void run() {
//stop animation after 5 seconds
deltaXAnimation.cancel();
}
}, 5000); //5000 equals to 5seconds
}
希望这可能对您有帮助
答案 1 :(得分:0)
嗨,有适当的回调方法可让您获得动画开始和结束监听器
ObjectAnimator deltaXAnimation =
ObjectAnimator.ofFloat(winMassage,"scaleX",1f,1.5f);
deltaXAnimation.setDuration(300);
deltaXAnimation.start();
deltaXAnimation.addListener(new Animator.AnimatorListener() {
@Override
public void onAnimationStart(Animator animator) {
}
@Override
public void onAnimationEnd(Animator animator) {
}
@Override
public void onAnimationCancel(Animator animator) {
}
@Override
public void onAnimationRepeat(Animator animator) {
}
});