我可以在前一个的onanimationEnd回调中启动Android动画吗?

时间:2011-01-05 07:25:50

标签: java android user-interface

我试图通过监视第一个动画的onanimationEnd回调来完成另一个动画。但是,当我尝试执行此操作时Android会出现以下错误:

错误 - AnimationUtils类型中的方法loadAnimation(Context,int)不适用于参数(new Animation.AnimationListener()  {},int)

我试着在这篇文章中使用答案: --- Android Animation one after other 我解释为我应该将除开始动画之外的所有内容移出回调,但是当我这样做时,我收到以下错误:

错误 - 无法引用在不同方法中定义的内部类中的非最终变量fade3

我在这里缺少什么?


******第一个例子的代码**********


package com.smartproducts.dragracepro;

import android.content.Intent;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.util.TypedValue;
import android.view.Gravity;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.Animation.AnimationListener;
import android.view.animation.AnimationUtils;
import android.view.animation.LayoutAnimationController;
import android.widget.ImageView;
import android.widget.TableLayout;
import android.widget.TableRow;
import android.widget.TextView;


public class DragRaceProSplashActivity extends DragRaceProActivity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) 
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.splash);

        //animate title fade in
        TextView programtitle = (TextView) findViewById(R.id.TextViewTopTitle);
        Animation fade1 = AnimationUtils.loadAnimation(this,R.anim.fade_in);
        programtitle.startAnimation(fade1);

        //show introduction and logo for Smart Shocks
        fade1.setAnimationListener(new AnimationListener(){         
            @Override
            public void onAnimationEnd(Animation fade1)
            {
***************  
ERROR IS HERE> Animation fade3 = AnimationUtils.loadAnimation(this,R.anim.fade_in2); ***************
            ImageView sslogo = (ImageView) findViewById(R.id.ImageView03);
                sslogo.setVisibility(View.VISIBLE);
                sslogo.startAnimation(fade3);
            }

            @Override
            public void onAnimationRepeat(Animation animation) {}

            @Override
            public void onAnimationStart(Animation animation) {}
        });

    }

1 个答案:

答案 0 :(得分:0)

Animation fade3 = AnimationUtils.loadAnimation(this,R.anim.fade_in2);

this指的是动画而不是你的上下文,因为你在监听器中调用它,如果你想使用这个代码,那么你需要创建一个你的上下文的全局变量并使用该变量this