2016-03-17 5 views
2

В моем приложении для Android у меня есть заставка, которая мигает логотипом приложения в течение 3 секунд, а затем запускает активность входа. Вот мой код:Blink imageView в течение нескольких секунд

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

I-й чернила из-за строки 'setRepeatCount (Animation.INFINITE)'. Проверьте описание [Animation.setRepeatCount] (http://developer.android.com/reference/android/view/animation/Animation.html#setRepeatCount (int)). –

+0

Вы пытались изменить его на определенное значение? –

ответ

2

Вы можете попробовать это

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

Я надеюсь, что это поможет вам. спасибо

0

Попробуйте

animation.setRepeatCount(1); 

вместо

animation.setRepeatCount(Animation.INFINITE); 
1

Заменить ниже линии

animation.setRepeatCount(Animation.INFINITE); 

с этим в коде

animation.setRepeatCount(1);