Android 恢复活动后停止动画效果
我在视图中添加了一些动画。Android 恢复活动后停止动画效果,android,animation,onresume,Android,Animation,Onresume,我在视图中添加了一些动画。 启动活动后,所有动画都将开始设置动画。停止动画效果后,我转到同一应用程序中的另一个活动。当我再次回到动画所在的活动时,所有动画都会再次开始动画,但这不是必需的 在活动中调用resume后,我需要停止该动画效果。我找不到任何解决办法。有什么建议吗 更新: 我添加了所有动画init并从onCreate()方法开始 更新: 动画在onCreate()方法中启动 sparkButton.setVisibility(View.GONE); welcomeLayo
启动活动后,所有动画都将开始设置动画。停止动画效果后,我转到同一应用程序中的另一个活动。当我再次回到动画所在的活动时,所有动画都会再次开始动画,但这不是必需的 在活动中调用resume后,我需要停止该动画效果。我找不到任何解决办法。有什么建议吗 更新: 我添加了所有动画init并从
onCreate()
方法开始
更新:
动画在onCreate()方法中启动
sparkButton.setVisibility(View.GONE);
welcomeLayout.setVisibility(View.VISIBLE);
AnimationSet animationSet = new AnimationSet(true);
animationSet.setFillEnabled(true);
animationSet.setInterpolator(new BounceInterpolator());
Animation animation1 = AnimationUtils.loadAnimation(this, R.anim.welcome_slide_right_left);
animation1.setDuration(700);
animationSet.addAnimation(animation1);
final AnimationSet animationSet2 = new AnimationSet(true);
ScaleAnimation animation2 = new ScaleAnimation(1.0f, 0.14f, 1.0f, 1.0f, Animation.RELATIVE_TO_SELF, 1.0f, Animation.RELATIVE_TO_SELF, 0.0f);
animation2.setDuration(400);
animation2.setStartOffset(400);
animationSet2.addAnimation(animation2);
animationSet.setAnimationListener(new Animation.AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {
}
@Override
public void onAnimationEnd(Animation animation) {
welcomeLayout.setAnimation(animationSet2);
}
@Override
public void onAnimationRepeat(Animation animation) {
}
});
animationSet2.setAnimationListener(new Animation.AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {
}
@Override
public void onAnimationEnd(Animation animation) {
welcomeLayout.setVisibility(View.GONE);
sparkButton.setVisibility(View.VISIBLE);
sparkButton.playAnimation();
}
@Override
public void onAnimationRepeat(Animation animation) {
}
});
welcomeLayout.setAnimation(animationSet);
我将源代码放在上面所示的位置。
这个问题需要澄清,我将把答案标记为黑客解决方案。如果这是否是我们没有正确处理的动画
对象的问题,这就是我想要解决的问题
更新:
单击“活动”按钮以转到另一个活动
case R.id.spark_button: {
// network checking code will append here
// after that calls the activity
startActivity(new Intent(SettingsActivity.this, HomeActivity.class));
break;
}
在调用startAnimation()的任何视图上调用clearAnimation()
希望这有帮助 为视图调用clearAnimation()
方法,该视图将在onStop()中设置动画
您的活动的方法
不在onResume
中,因为它在活动首次启动时也会触发您可以尝试将启动动画代码置于onCreate中的类似条件中
if(null == savedBundleState) {
////Play your Animation
}
您可以创建布尔值,并在活动开始时始终进行检查
boolean shouldShowAnimation = true;
@Override
public void onResume(){
super.onResume();
if(shouldShowAnimation) {
shouldShowAnimation = false;
// Your animation
}
}
我在onStop()
方法上调用了clearAnimation()
,但仍然存在相同的问题,只是想确认您是否在onResume方法中设置了视图的动画,如果是,请将该部分转到onCreate方法对不起,我的道歉请在onPasue
方法中调用clearAnimation()方法仍然是同一个家伙。还有其他建议吗?请告诉我当savedBundleState==null时,您实际在哪里添加startAnimation代码这意味着活动刚刚开始,因此,请发布您的代码您如何在这些活动之间导航?我使用上面的sparkButton导航到另一个活动,我使用Intent
导航到活动我没有看到Intent代码,您从按钮更新线程@userone启动活动的代码我想检查您是否没有调用finish(),我的答案应该是这样的,当您恢复时,检查savedBundleState是否为null(从活动B返回到A),它应该为空