几秒钟闪烁ImageView

4

在我的安卓应用中,我有一个启动页面,它会闪烁应用的标志三秒钟,然后开始登录活动。

以下是我的代码:

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秒后停止闪烁?我参考了一些帖子,但没有得到确切的答案。


2
我认为问题出在 setRepeatCount(Animation.INFINITE) 这一行代码上。请查看 Animation.setRepeatCount 的描述。 - AL.
你尝试将它更改为特定的值了吗? - AL.
一个简单的 BlinkerView 可以解决问题 - 可以看看我的答案:https://dev59.com/iuo6XIcBkEYKwwoYIAcL#50299715 - 唯一需要注意的是要自己停止闪烁。你可以通过向处理程序发送消息来实现,就像其他人建议的那样。 - milosmns
3个回答

6
你可以尝试这个。
      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);

您可以使用代替。
希望这能帮到您。谢谢。

0

尝试

animation.setRepeatCount(1);

而不是

animation.setRepeatCount(Animation.INFINITE);

0

替换下面这行代码

animation.setRepeatCount(Animation.INFINITE);

在你的代码中加入这个

 animation.setRepeatCount(1);

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接