0

当我的应用程序加载时,我让它为屏幕设置动画。在 onAnimationEnd 中,我调用 schedule 让它在 2 秒后调用一个函数,该函数将调用一个动画来再次为视图设置动画。目前它动画,但调度程序似乎永远不会调用动画。如果我单击主页,然后返回应用程序,它会立即调用动画。为什么,如果计划正在运行,应用程序会等到它失去焦点然后重新获得焦点以实际触发计划应该调用的函数。这是代码:

这些在 onCreate 中定义:

slideTopIn = AnimationUtils.loadAnimation(this, R.anim.slide_top_in);
slideTopIn.setAnimationListener(slideTopInListener);
slideTopOut = AnimationUtils.loadAnimation(this, R.anim.slide_top_out);
slideTopOut.setAnimationListener(slideTopOutListener);

freeAlertMsg.startAnimation(slideTopIn);

这些是在活动类中的 onCreate 之外定义的:

private AnimationListener slideTopInListener = new AnimationListener(){
    public void onAnimationEnd(Animation anim){
        alertTimer.schedule(new Runnable() {
            public void run() { hideFreeAlert(); }
        }, 2, TimeUnit.SECONDS);
    };
    public void onAnimationStart(Animation anim){
        freeAlertMsg.setVisibility(View.VISIBLE);
    };
    public void onAnimationRepeat(Animation anim){

    };
};

private AnimationListener slideTopOutListener = new AnimationListener(){
    public void onAnimationEnd(Animation anim){
        mainScreen.removeView(freeAlert);
    };
    public void onAnimationStart(Animation anim){
        Log.d("Animation Listener","slideTopOutListener");
    };
    public void onAnimationRepeat(Animation anim){

    };
};

private void hideFreeAlert(){
    freeAlertMsg.startAnimation(slideTopOut);
}

所以基本上它执行 startAnimation(slideTopIn)。然后什么也没有发生。如果我单击主页,然后返回应用程序,startAnimation(slideTopOut) 将立即执行。我猜计划实际上是在运行,但由于某种原因从未触发过动画。

4

1 回答 1

1

随便叫postDelayed()一个View

于 2010-11-14T23:33:29.377 回答