我想在切换到新活动之前在图像上执行动画.我还想确保在新活动开始之前动画完全完成.下面是我用来完成任务的代码.
public boolean onTouch(View view, MotionEvent event) {
Animation shake = AnimationUtils.loadAnimation(ViewReadingActivity.this, R.anim.shake);
imgAries.startAnimation(shake);
Intent intent = new Intent(ViewReadingActivity.this, ShowHoroActivity.class);
startActivity(intent);
return true;
}
Run Code Online (Sandbox Code Playgroud)
这个问题是动画在呈现新活动之前没有运行完成,动画将从它离开的地方继续运行.有没有更好的方法来实现这一目标?
在这里使用你可以有动画列表
shake.setAnimationListener(new AnimationListener() {
@Override
public void onAnimationStart(Animation arg0) {
// TODO Auto-generated method stub
}
@Override
public void onAnimationRepeat(Animation arg0) {
// TODO Auto-generated method stub
}
@Override
public void onAnimationEnd(Animation arg0) {
Intent intent = new Intent(ViewReadingActivity.this, ShowHoroActivity.class);
startActivity(intent);
}
});
Run Code Online (Sandbox Code Playgroud)