我正在尝试使用AnimatorSet
Button fades in > Click button > Remaining buttons fade out
所以为了做到这一点,我想设置onClickListner after the animation is completed
,但这似乎不起作用。单击动画triggers the onClick action
中间的按钮:
setQuestion = new AnimatorSet();
setQuestion.playSequentially(fadeinAnimationQ,fadeinAnimation1,fadeinAnimation2,fadeinAnimation3,fadeinAnimation4,fadeinAnimation5);
setQuestion.start();
这是检查if the animation has finished
。
private void checkAnimation() {
while (true) {
// Check if animation has ended
if (setQuestion.isRunning() == false) {
assignListners();
break;
}
}
}
答案 0 :(得分:40)
您可以在fadeinAnimation5上设置AnimatorListener。 这将为您提供onAnimationEnd回调。
fadeinAnimation5.addListener(new AnimatorListener() {
@Override
public void onAnimationStart(Animator animation) {
// ...
}
@Override
public void onAnimationRepeat(Animator animation) {
// ...
}
@Override
public void onAnimationEnd(Animator animation) {
// ...
}
@Override
public void onAnimationCancel(Animator animation) {
// ...
}
});
或者,根据slott的建议,使用AnimatorListenerAdapter
fadeinAnimation5.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
// ...
}
}
答案 1 :(得分:1)
我遇到了类似的问题,这就是我解决问题的方法:
for
答案 2 :(得分:0)
由于AnimatorSet继承自Animator,因此您实际上可以直接将监听器设置为AnimatorSet。这是一些代码:
import android.animation.Animator;
AnimatorSet setQuestion = new AnimatorSet();
setQuestion.playSequentially(fadeinAnimationQ,fadeinAnimation1,fadeinAnimation2,fadeinAnimation3,fadeinAnimation4,fadeinAnimation5);
setQuestion.addListener(new Animator.AnimatorListener() {
@Override
public void onAnimationStart(Animator animator) {
}
@Override
public void onAnimationEnd(Animator animator) {
// !! turn on your onClickListener here !!
}
@Override
public void onAnimationCancel(Animator animator) {
}
@Override
public void onAnimationRepeat(Animator animator) {
}
});
setQuestion.start();