Android animationlistener和intent
构建活动的最佳实践是什么?活动应该从显示动画图像开始,然后在动画完成后通过意图移动到另一个“活动”?我理解一些基本原则,但我在构建流程时迷失了方向Android animationlistener和intent,android,animation,Android,Animation,构建活动的最佳实践是什么?活动应该从显示动画图像开始,然后在动画完成后通过意图移动到另一个“活动”?我理解一些基本原则,但我在构建流程时迷失了方向 public class Scanimation extends Activity { //create name of animation Animation myFadeInAnimation; /** Called when the activity is first created. */ @Override public v
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);
}
}
我读过的大多数教程似乎都使用这种类型的流。我拉入我的主布局和视图,然后设置特定视图的动画,并快速振动设备一秒钟。动画结束时,启动下一个或最后一个活动的意图不会激发
我在这里遗漏了什么?我看不到您在哪里调用
setAnimationListener()
将al
与myFadeInAnimation
关联。当然,我也看不到您实际在哪里创建myFadeInAnimation
。我看不到您在哪里调用setAnimationListener()
将al
与myFadeInAnimation
关联。当然,我也看不出您实际上在哪里创建了myFadeInAnimation
。以下是正确的版本:
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);
}
}
以下是更正的版本:
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);
}
}
谢谢你的新鲜表情,这对我来说是一个相当沮丧的练习。看了几个小时,我的眼睛都被打伤了,明天我再试试看,看看你提到的两件事。Commonware,谢谢你指出我错过了什么。我花了大约15分钟重新构造代码,并注意您的观察结果。我能够创建代码并使其工作。我想我应该发布新版本,以防其他人想看到它。现在我只需要想一想如何在暂停后重新启动它(即,退出接听电话,然后再回来)谢谢你的新外观,这对我来说是一个相当沮丧的练习。看了几个小时,我的眼睛都被打伤了,明天我再试试看,看看你提到的两件事。Commonware,谢谢你指出我错过了什么。我花了大约15分钟重新构造代码,并注意您的观察结果。我能够创建代码并使其工作。我想我应该发布新版本,以防其他人想看到它。现在我只需要弄清楚如何在暂停后重新启动它(即,退出接听电话,然后再回来)