gpt4 book ai didi

Android 应用加载屏幕背景图片加载时间过长

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:06:03 24 4
gpt4 key购买 nike

我正在开发一个安卓应用。在我的例子中,当应用程序启动时,它会显示一个临时屏幕,而 AsyncTask 在后台获取数据。此临时屏幕仅包含背景图像 (20 KB)。但是在此背景下需要一段时间才能加载。因此,当我启动我的应用程序时,我只看到一个白色屏幕,过了一会儿它显示了背景图像。关于如何摆脱这个问题并从一开始就显示背景图片的任何想法这是开始屏幕的xml文件

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/start"
android:orientation="vertical" >

</LinearLayout>

谢谢

最佳答案

我遇到了同样的问题。这个了不起的人有explanation .

TL;DR(只有在链接变坏的情况下,我才会去阅读它):“预览窗口的目的是向用户提供应用启动的即时反馈,但它也让您的应用有时间进行初始化本身。当您的应用程序准备好运行时,系统会删除该窗口并显示您的应用程序的窗口和 View 。”您可以在主题中设置它。至少,我的设置:

/res/values/styles.xml 中的主题:

<resources>

<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="android:windowBackground">@drawable/app_bg</item>
</style>
<!-- Base theme for any other activity other than your starting one. -->
<!-- If only one activity, just set the splash bg as its bg -->
<style name="MyTheme.MainActivity" parent="@style/AppTheme">
<item name="android:windowBackground">@drawable/app_splash_bg</item>
</style>

</resources>

AndroidManifest.xml:

...
<activity
android:name=".MainActivity"
android:theme="@style/MyTheme.MainActivity"
...
<!-- Set the MainActivity theme, can be skipped if you only have -->
<!-- one activity and did not setup anything other than your base theme -->

主要 Activity .java:

@Override
protected void onResume() {
super.onResume();
MainActivity.this.getWindow().setBackgroundDrawableResource(R.drawable.app_bg);
}

基本上,您可以为开始的 Activity 设置一个带有启动背景的主题。然后,在所述开始 Activity 的 onResume 期间将背景设置为正常背景。

此外,您可以在启动 Activity 主题中注释掉 windowBackground 声明,以在启动时看到原始的(我假设)“丑陋的白色”屏幕。

关于Android 应用加载屏幕背景图片加载时间过长,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14572833/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com