您如何告诉功能在Kotlin中等待几秒钟? [英] How do you tell a function to wait a few seconds in Kotlin?

查看:145
本文介绍了您如何告诉功能在Kotlin中等待几秒钟?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

此处是Android Studio中的Kotlin.

Kotlin in Android Studio here.

我正在尝试使imageView淡入主视图,等待几秒钟,然后淡出.为了我的一生,我找不到任何有关暂停或等待任何地方的文档.真让我发疯.

I'm trying to get an imageView to fade into the main view, wait a few seconds, then fade out. For the life of me I can't find any documentation on pausing or waiting anywhere. It's driving me nuts.

如何告诉我的函数放松一下并等待3秒钟,然后继续执行该函数的其余代码?

How do I tell my function to just chill out and wait for 3 seconds, then continue executing the rest of the function's code?

理想情况下,我希望在之间:

Ideally, I would have it between:

imageView.startAnimation(animIn)
imageView.startAnimation(animOut)

非常感谢您的帮助!

动物园

推荐答案

您可以使用处理程序

Handler().postDelayed(Runnable { 
    //anything you want to start after 3s
}, 3000)

这篇关于您如何告诉功能在Kotlin中等待几秒钟?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆