开发者

Can I launch an Android animation in the onanimationEnd callback of the previous one?

开发者 https://www.devze.com 2023-02-02 06:15 出处:网络
I am attempting to launch one animation after another has finished by monitoring the onanimationEnd callback of the first on开发者_如何转开发e. However Android gives the following error when I attempt

I am attempting to launch one animation after another has finished by monitoring the onanimationEnd callback of the first on开发者_如何转开发e. However Android gives the following error when I attempt to do this:

Error - The method loadAnimation(Context, int) in the type AnimationUtils is not applicable for the arguments (new Animation.AnimationListener() {}, int)

I tried to use the answer in this post: ---Android Animation one after other Which I interpreted to mean that I should move everything except the start animation out of the callback, but when I do this I get the following error:

Error - Cannot refer to a non-final variable fade3 inside an inner class defined in a different method

What am I missing here???


******CODE FOR FIRST EXAMPLE**********


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

    }


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

this is referring to the animation instead of your context as your calling it inside of a listener, If you want to use this code then you need to create a global variable of your context and use that variable in place of this.

0

精彩评论

暂无评论...
验证码 换一张
取 消