简体   繁体   English

按钮动画后,如何使下一个活动等待几秒钟?

[英]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.

相关问题 如何让我的死亡菜单在玩家死亡后等待 3 秒设置为活动状态? - how do i make my death menu wait 3 seconds to set active after the player died? 动画:访问其他活动并回来后如何重复播放动画? - Animation: How do I make animation to repeat after I visit another activity and come back? 如何制作启动画面结束动画并开始下一个活动? - How do I make a splash screen end animation and start next activity? 5秒后如何在我的主xml上显示图像按钮? - how do i make an image button to come up on my main xml after 5 seconds? 如何做到这一点,以便在按下Activity2的后退按钮后可以使屏幕在Activity1上向下滚动更多? - How do I make it so I can have the screen scrolled down more on Activity1 after pressing the back button on Activity2? 如何将按钮切换到新活动? - How do I make a button switch to a new activity? 动画结束后如何更改活动? 动画侦听器似乎不起作用 - How do I change the activity after animation ends? Animation listener doesnt seem to be working 我如何进行从按钮到新活动的 animation 转换?[Android Studio] - How i can make a animation transition that start from a button to a new activity?[Android Studio] 如何使活动在基于Intent切换到新布局之前等待? - How do I make the Activity wait before it switches to the new layout based on an Intent? 你如何让android中的代码暂停几秒钟? - How do you have the code pause for a couple of seconds in android?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM