我的缩放/缩放动画不会以finish()开头。我希望有一种方法可以在不删除上述声明的情况下完成,因为有必要不回到当前的活动。
以下是代码:
package com.capstone.mainmobidyx.filipino;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.Button;
import com.capstone.mainmobidyx.R;
public class F_FilipinoYunit1 extends Activity implements OnClickListener {
Button btnLesson1, btnLesson2, btnLesson3;
Intent lesson1, lesson2, lesson3;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.f_yunit1);
btnLesson1 = (Button) findViewById(R.id.btnY1Lesson1);
btnLesson1.setOnClickListener(this);
btnLesson2 = (Button) findViewById(R.id.btnY1Lesson2);
btnLesson2.setOnClickListener(this);
btnLesson3 = (Button) findViewById(R.id.btnY1Lesson3);
btnLesson3.setOnClickListener(this);
}
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
final Animation zoomAnim = AnimationUtils.loadAnimation(this,R.anim.zoom_in);
v.startAnimation(zoomAnim);
switch (v.getId()) {
case R.id.btnY1Lesson1:
lesson1 = new Intent(v.getContext(), SX_Lesson01.class);
startActivity(lesson1);
finish();
break;
case R.id.btnY1Lesson2:
lesson2 = new Intent(v.getContext(),
SX_ScienceLesson02Menu.class);
startActivity(lesson2);
finish();
break;
case R.id.btnY1Lesson3:
lesson2 = new Intent(v.getContext(),
SX_Lesson03Menu.class);
startActivity(lesson2);
finish();
break;
}
}
}
解决方案:
使用onAnimation end方法。我现在可以在完成活动之前通过在方法中插入代码来启动动画。
这是工作代码:
@Override
public void onClick(final View v) {
// TODO Auto-generated method stub
final Animation zoomAnim = AnimationUtils.loadAnimation(this,R.anim.zoom_in);
zoomAnim.setAnimationListener(new AnimationListener() {
public void onAnimationEnd(Animation anim) {
switch (v.getId()) {
case R.id.btnY1Lesson1:
lesson1 = new Intent(v.getContext(), SX_Lesson01.class);
startActivity(lesson1);
finish();
break;
case R.id.btnY1Lesson2:
lesson2 = new Intent(v.getContext(),
SX_ScienceLesson02Menu.class);
startActivity(lesson2);
finish();
break;
case R.id.btnY1Lesson3:
lesson2 = new Intent(v.getContext(),
SX_Lesson03Menu.class);
startActivity(lesson2);
finish();
break;
}
}
}
public void onAnimationRepeat(Animation arg0) {}
public void onAnimationStart(Animation arg0) {}
});
v.startAnimation(zoomAnim);
答案 0 :(得分:1)
在动画上设置动画结束侦听器,在动画结束时设置finish()/ startActivity():
http://developer.android.com/reference/android/view/animation/Animation.AnimationListener.html
示例:
final Animation animation = AnimationUtils.loadAnimation(this,R.anim.zoom_in);
animation.setAnimationListener(new AnimationListener() {
public void onAnimationEnd(Animation anim) {
// Start your new activity and finish() the current activity here!
}
public void onAnimationRepeat(Animation arg0) {}
public void onAnimationStart(Animation arg0) {}
}
animation.startAnimation()