animationlistener和intent

时间:2010-10-20 18:40:45

标签: android animation

构建活动的最佳做法是什么,应该首先显示动画图像,然后在动画完成时按意图移动到另一个“活动”?我理解一些基本原则,但我在这里构建流程时迷失了方向。

public class Scanimation extends Activity  { 

 //create name of animation 
Animation myFadeInAnimation;

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

//grab the imageview from the layout, and then load the animation listener
      ImageView myImageView = (ImageView) findViewById(R.id.blinkingView01);
      AnimationListener al= new AnimationListener() {

    public void onAnimationStart(Animation animation) {
    // do nothing       
    }

    public void onAnimationRepeat(Animation animation) {
    // do nothing       
    }

        // at the end of the animation, start new activity
    public void onAnimationEnd(Animation animation) {
        Intent myIntent = new Intent (view.getContext(), LastActivity.class);
         startActivity(myIntent);               
    }

     // get the animation effects which are in the XML file and defines how to animate it       Animation myFadeInAnimation = AnimationUtils.loadAnimation(this, R.anim.fade_in);

};

     //okay now start the animation on screen
     myImageView.startAnimation(myFadeInAnimation); 

    // go get the vibration service and vibrate quickly while screen is animated           
    Vibrator v = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
long milliseconds = 2000;
v.vibrate(milliseconds);
long[] pattern = { 500, 300 };
v.vibrate(pattern, -1);

      }

   }

我读过的大多数教程似乎都使用这种类型的流程。我正在进行主要布局和视图,然后设置特定视图的动画以及快速振动设备。在动画结束时,启动下一个或上一个活动的意图不会触发。

我在这里缺少什么?

2 个答案:

答案 0 :(得分:2)

我看不到您要将setAnimationListener()al联系起来myFadeInAnimation。当然,我也没有看到你实际创建myFadeInAnimation的位置。

答案 1 :(得分:2)

以下是更正后的版本:

public class Scanimation extends Activity implements     AnimationListener{ 

 public Animation myFadeInAnimation;

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

    ImageView myImageView = (ImageView) findViewById(R.id.blinkingView01);
    myFadeInAnimation = AnimationUtils.loadAnimation(this, R.anim.fade_in);   

    myFadeInAnimation.setAnimationListener(this);
    myImageView.startAnimation(myFadeInAnimation);
}

        public void onAnimationEnd(Animation animation) {
            Intent myIntent = new Intent (this, Lastactivity.class);
            startActivity (myIntent);                       
     } 

        public void onAnimationRepeat(Animation animation) { 

     } 

        public void onAnimationStart(Animation animation) { 
            // go get the vibrator service         
            Vibrator v = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);

            // 1. Vibrate for 2000 milliseconds
            long milliseconds = 2000;
            v.vibrate(milliseconds);

            // 2. Vibrate in a Pattern 
            long[] pattern = { 500, 300 };
            v.vibrate(pattern, -1);
     } 
}