闪烁 imageView 几秒钟

Blink imageView for few seconds

在我的 android 应用程序中,我有一个闪屏,它会闪烁应用程序的徽标 3 秒钟,然后开始登录 activity。 这是我的代码:

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();

希望对您有所帮助。谢谢

尝试

animation.setRepeatCount(1);

而不是

animation.setRepeatCount(Animation.INFINITE);

替换下行

animation.setRepeatCount(Animation.INFINITE);

在你的代码中加入这个

 animation.setRepeatCount(1);