2016-11-26 9 views
0

У меня есть вид GifImageButton. Я хочу начать анимацию, а затем перезапустить ее.Задержка анимации перед перезапуском активности

проблема заключается в том, что я хочу, чтобы анимация продолжалась за 3 секунды до перезапуска активности.

Как я могу это сделать?

это мой код:

myGifImageButton.setImageResource(R.drawable.animation); 
Intent intent = getIntent(); 
finish(); 
if (intent != null) { 
    startActivity(intent); 
} 

Как я прочитал, лучший способ заключается в использовании работоспособной, поэтому я попытался это, но мне не удалось его:

// start the animation 
myGifImageButton.setImageResource(R.drawable.animation); 

// delay the animation 
mHandler = new Handler(); 
final Runnable r = new Runnable() { 
    void run() { 
     handler.postDelayed(this, 3000); 
    } 
}; 
handler.postDelayed(r, 3000); 

// restart the activity 
Intent intent = getIntent(); 
finish(); 
if (intent != null) { 
    startActivity(intent); 
} 

так как я могу отложить анимацию перед перезапуском?

ответ

1

Yor runnable является неправильным - вы постоянно перепродаете ту же производительность, которая ничего не делает.

Вместо попробовать что-то вроде этого:

// start the animation 
myGifImageButton.setImageResource(R.drawable.animation); 

// delay the animation 
mHandler = new Handler(); 
final Runnable r = new Runnable() { 
    void run() { 
     // restart the activity 
     Intent intent = getIntent(); 
     finish(); 
     if (intent != null) { 
      startActivity(intent); 
     } 
    } 
}; 
handler.postDelayed(r, 3000); 
+0

King !! благодаря! Я получил смысл «бегать» сейчас .. :) –