[英]Less fps in loading screen of my android app
`I have written this code for loading screen of my android app. `我已经为我的 android 应用程序的加载屏幕编写了这段代码。 But whenever i install it on my phone the fps of my loading screen is very low seems like it has 2-3 fps The loading screen is a gif file.
但是每当我将它安装在我的手机上时,我的加载屏幕的 fps 非常低,似乎只有 2-3 fps 加载屏幕是一个 gif 文件。
class splash_screen:AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_splash_screen)
val gifImageView = findViewById<ImageView>(R.id.loading_gif)
Glide.with(this).asGif().load(R.drawable.loading_gif).into(gifImageView)
val background = object : Thread() {
override fun run() {
try {
Thread.sleep(5000)
val intent = Intent(baseContext, MainActivity::class.java)
startActivity(intent)
} catch (e: Exception) {
e.printStackTrace()
}
}
}
background.start()
}
}
` `
You can use coroutine instead of regular thread.您可以使用协程而不是常规线程。
CoroutineScope(Dispatchers.IO).launch {
delay(TimeUnit.SECONDS.toMillis(5))
withContext(Dispatchers.Main) { startActivity(Intent(baseContext, MainActivity::class.java)) }
}
Dont forget to add coroutines to your dependencies in your app's build.gradle不要忘记将协程添加到应用程序的依赖项中 build.gradle
dependencies {
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-android:1.3.9")
}
You can read more about them here: https://reflectoring.io/understanding-kotlin-coroutines-tutorial/#:~:text=Coroutines%20are%20more%20efficient%20than,for%20the%20coroutines%20to%20complete .你可以在这里阅读更多关于它们的信息: https://reflectoring.io/understanding-kotlin-coroutines-tutorial/#:~:text=Coroutines%20are%20more%20efficient%20than,for%20the%20coroutines%20to%20complete 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.