[英]After button animation, how do I make the next activity wait a couple of seconds?
I want to know if there is a way to make the app wait like 2-3 seconds after it does a button animation (pulsingAnimation.start()) so that after those three seconds it will do the next code in line which is to create an intent and start a new activity/finish the last one. 我想知道是否有一种方法可以让应用程序在执行按钮动画(pulsingAnimation.start())之后等待2-3秒,以便在这三秒钟后它将执行要创建的下一行代码一种意图并开始一项新活动/完成最后一项。 Here is my code. 这是我的代码。 Please help, thanks! 请帮忙,谢谢!
final Button Metric = (Button) findViewById(R.id.button2);
final RelativeLayout r = (RelativeLayout) findViewById(R.id.relativeLayout6);
final ObjectAnimator pulsingAnimation = ObjectAnimator.ofPropertyValuesHolder(r,
PropertyValuesHolder.ofFloat("scaleX", 1.2f),
PropertyValuesHolder.ofFloat("scaleY", 1.2f));
pulsingAnimation.setRepeatCount(ObjectAnimator.INFINITE);
pulsingAnimation.setRepeatMode(ObjectAnimator.REVERSE);
Metric.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
pulsingAnimation.start();
Intent i = new Intent(MainActivity.this, Metric.class);
startActivity(i);
finish();
}
});
Look into using a delayed handler http://developer.android.com/reference/android/os/Handler.html#postDelayed(java.lang.Runnable , long) 查看使用延迟的处理程序http://developer.android.com/reference/android/os/Handler.html#postDelayed(java.lang.Runnable,long )
eg: 例如:
handler = new Handler();
runnable = new Runnable() {
@Override
public void run() {
//do something
}
};
handler.postDelayed(runnable, 2000);
You can sleep for some milliseconds with the Thread.sleep(milliseconds) function. 您可以使用Thread.sleep(milliseconds)函数休眠几毫秒。 Take a look to this link https://docs.oracle.com/javase/tutorial/essential/concurrency/sleep.html 看一下此链接https://docs.oracle.com/javase/tutorial/essential/concurrency/sleep.html
Easy way to do this: 简便的方法:
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
Intent i = new Intent(MainActivity.this, Metric.class);
startActivity(i);
finish();
}
}, 3000); // 3000 - 3 seconds, 2000 - 2 seconds
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.