gpt4 book ai didi

android - 如何确保在执行下一条指令之前允许动画完成?

转载 作者:行者123 更新时间:2023-11-29 02:07:48 24 4
gpt4 key购买 nike

我是 Android 开发的新手,我创建了一个与按钮 onClick Action 相关联的动画,但是在执行下一个命令之前动画似乎没有完成。我知道动画有效,因为如果我注释掉 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();
}
});

最佳答案

设置动画监听器并 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.....

}
});

关于android - 如何确保在执行下一条指令之前允许动画完成?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9032392/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com