0

我有一个片段,onCreateDialog()我在其中启动了一个后台线程,它最终调用了这个方法:

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

handler创建onCreateDialog()于. 后续调用按showMessageWithProgressWhenEmpty()预期制作动画。对这个方法的第一次调用(没有正确动画的那个)发生在调用onCreateDialog().

我已经看到提到动画在启动时不起作用的答案Activity.onCreate(),这就是为什么我要post调用handler.

我在这里想念什么?

4

1 回答 1

2
protected void showMessageWithProgressWhenEmpty(final String message) {

        textView.setText(message);
        textView.setCompoundDrawablesWithIntrinsicBounds(
            R.drawable.anim_spin_refresh, 0, 0, 0
        );
        AnimationDrawable anim = (AnimationDrawable)textView.getCompoundDrawables()[0];
       // run the start() method later on the UI thread
        textView.post(new Starter());
}
 class Starter implements Runnable {

        public void run() {
            anim.start();
        }

设置文本视图后调用启动器

于 2013-04-13T05:46:01.417 回答