简体   繁体   中英

Blink imageView for few seconds

In my android application, I have a splash screen which blinks the logo of the app for 3 seconds and then start the login activity. Here is my code:

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

But the image blinks infinitely. How to stop blinking after 3 seconds? I referred some posts but I could not get an exact answer.

You can try this

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

You can use imgView.clearAnimation() instead of animation.cancel();

I hope this will help you. thanks

Replace below line

animation.setRepeatCount(Animation.INFINITE);

with this in your code

 animation.setRepeatCount(1);

Try

animation.setRepeatCount(1);

instead of

animation.setRepeatCount(Animation.INFINITE);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM