我有一個奇怪的問題,AlphaAnimation
。當調用AsyncTask
處理程序時,它應該重複運行。直到UI更新或觸摸事件纔開始動畫
但是,第一次在Activity
中調用處理程序時,除非我觸摸屏幕或更新UI(例如按手機的菜單按鈕),否則動畫將不會啓動。
奇怪的部分是,一旦動畫運行至少一次,如果再次調用處理程序,它將毫無問題地啓動。
下面的代碼是什麼樣子:
// AsyncTask handler
public void onNetworkEvent()
{
this.runOnUiThread(new Runnable() {
@Override
public void run()
{
flashScreen(Animation.INFINITE);
}
});
}
// Called method
private void flashScreen(int repeatCount)
{
final View flashView = this.findViewById(R.id.mainMenuFlashView);
AlphaAnimation alphaAnimation = new AlphaAnimation(1, 0);
alphaAnimation.setRepeatCount(repeatCount);
alphaAnimation.setRepeatMode(Animation.RESTART);
alphaAnimation.setDuration(300);
alphaAnimation.setInterpolator(new DecelerateInterpolator());
alphaAnimation.setAnimationListener(new Animation.AnimationListener() {
@Override
public void onAnimationStart(Animation animation)
{
flashView.setVisibility(View.VISIBLE);
}
@Override
public void onAnimationEnd(Animation animation)
{
flashView.setVisibility(View.GONE);
}
@Override
public void onAnimationRepeat(Animation animation) { }
});
flashView.startAnimation(alphaAnimation);
}
我注意到,runOnUIThread
是沒有必要的(如果我不使用相同的結果發生),但我更喜歡保持它作爲我不是在UI線程上。
有什麼想法可能導致這種情況?
太少的代碼來理解你的呼叫順序。你能發佈圍繞Asynctask執行的部分嗎?另外,您是否嘗試將條目記錄到相關方法以查看發生了什麼? – ilomambo 2013-04-26 14:50:22
嘗試第一次延遲動畫幾秒鐘。在視圖準備好之前嘗試運行動畫時,可能會出現這種情況。 – 2013-04-26 14:51:01