我是Android Studio新手。我想在按钮的动画和第二个活动的打开之间放置延迟,这样动画就会运行,然后会打开splashActivity。
btn.setOnClickListener(new View.OnClickListener(){
public void onClick(View arg0){
Animation anim4 = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.splash_anim);
btn.startAnimation(anim4);
startActivity(new Intent(MainActivity.this, splashActivity.class));
}
});
答案 0 :(得分:0)
int Delay_time_of_animation = 500;
btn.setOnClickListener(new View.OnClickListener(){ public void onClick(查看arg0){
Animation anim4 = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.splash_anim);
btn.startAnimation(anim4);
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
startActivity(new Intent(MainActivity.this, splashActivity.class));
}
}, Delay_time_of_animation);
}
});
答案 1 :(得分:0)
我使用本机java Timer来延迟。如果你想在两种方法之间延迟,那么你必须以毫秒为单位传递延迟时间。
int DELAY_TIME=2000
//start your animation
new Timer().schedule(new TimerTask() {
@Override
public void run() {
//this code will run after the delay time which is 2 seconds.
startActivity(new Intent(MainActivity.this, splashActivity.class));
}
}, DELAY_TIME);
2000毫秒意味着你可以增加2秒的时间