我在哪裏我onCreateDialog()
啓動一個後臺線程,最終調用這個方法的片段在第一時間:動畫無法啓動,即使在Handler.post()開始
protected void showMessageWithProgressWhenEmpty(final String message) {
handler.post(new Runnable() {
textView.setText(message);
textView.setCompoundDrawablesWithIntrinsicBounds(
R.drawable.anim_spin_refresh, 0, 0, 0
);
AnimationDrawable anim = (AnimationDrawable)textView.getCompoundDrawables()[0];
anim.start();
}
}
在onCreateDialog()
,創建handler
。後續調用showMessageWithProgressWhenEmpty()
有意動畫。在對onCreateDialog()
的調用約1秒內發生第一次對此方法的調用(沒有正確動畫的調用)。
我已經看到答案,提到動畫在Activity.onCreate()
開始時不起作用,這就是爲什麼我要post
致電handler
。
我在這裏錯過了什麼?
收到一些問題,動畫,沒有完全相同的問題,你有,但我不得不無效視圖。 在setCompoundDrawablesWithIntrinsicBounds和啓動方法之後嘗試invalidate()。 – Alex
我試圖在'setCompoundDrawablesWithIntrinsicBounds'以及'anim.start()'之後調用'invalidate()',但不起作用。任何其他想法? –
textView.startAnimation(anim)? ,只是猜測。儘管這看起來像是在視圖實際「創建」之前嘗試啓動動畫。可能在您的DialogFragment中尋找像onStart這樣的函數,而不是您現在使用的onCreateDialog – Alex