我是Android开发的新手,我创建了一个动画,我已经将其与onClick动作相关联,但是在执行下一个命令之前动画似乎没有完成。我知道动画是有效的,因为如果我注释掉openWallet()命令,我可以看到它按预期运行。有什么想法,我可以确保动画在执行openWallet()之前完成? openWallet()加载一个不同的xml布局,所以我怀疑动画可能会在后台进行?
private Button useButton;
private Animation buttonPulseAnimation = null;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.front_portrait);
useButton = (Button) findViewById(R.id.icon_image);
buttonPulseAnimation = AnimationUtils.loadAnimation(this, R.anim.button_pulse);
useButton.startAnimation(buttonPulseAnimation);
useButton.setOnClickListener(new View.OnClickListener(){
public void onClick(View v){
useButton.startAnimation(buttonPulseAnimation);
openWallet();
}
});
答案 0 :(得分:1)
设置动画侦听器,onAnimationEnd
执行下一个任务:
buttonPulseAnimation.setAnimationListener(new Animation.AnimationListener() {
public void onAnimationStart(Animation animation) {
// TODO Auto-generated method stub
}
public void onAnimationRepeat(Animation animation) {
// TODO Auto-generated method stub
}
public void onAnimationEnd(Animation animation) {
// Define your next task here.....
}
});