在我的Android应用程序中,我有一个闪屏,它会使应用程序的徽标闪烁3秒,然后启动登录活动.
这是我的代码:
imgView.postDelayed(new Runnable() {
@Override
public void run() {
final Animation animation = new AlphaAnimation(1, 0);
animation.setDuration(1000);
animation.setInterpolator(new LinearInterpolator());
animation.setRepeatCount(Animation.INFINITE);
animation.setRepeatMode(Animation.REVERSE);
imgView.startAnimation(animation);
}
}, 3000);
Intent intent = new Intent(SplashscreenActivity.this,LoginActivity.class);
startActivity(intent);
但是图像无限闪烁.如何在3秒后停止闪烁?我提到了一些帖子,但我无法得到确切的答案.
解决方法:
你可以试试这个
final Animation animation = new AlphaAnimation(1, 0);
animation.setDuration(1000);
animation.setInterpolator(new LinearInterpolator());
animation.setRepeatCount(Animation.INFINITE);
animation.setRepeatMode(Animation.REVERSE);
imgView.startAnimation(animation);
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
animation .cancel();
Intent intent = new Intent(SplashscreenActivity.this, LoginActivity.class);
startActivity(intent);
}
}, 3000);
您可以使用imgView.clearAnimation()代替animation.cancel();
我希望这能帮到您.谢谢