【发布时间】:2016-05-20 00:11:03
【问题描述】:
我决定在我的应用开始时创建一个启动画面。我创建了一个 1600x900 的图像并将其用作可绘制对象。当我运行我的应用程序时,似乎每个动作都有 1 秒的延迟。检查完所有内容后,我意识到这是闪屏以某种方式导致了这种滞后。测试表明,以这种方式制作成可绘制对象的高分辨率图像会导致延迟,我不知道为什么。
我的图像重 100kb,我逐渐降低了分辨率和大小,延迟也逐渐降低。我还制作了一张 5kb 的高分辨率图像,并且延迟仍然存在,这意味着分辨率主要是罪魁祸首。
为什么会发生这种情况,我怎样才能在没有后续影响的情况下创建启动画面?
代码:
风格:
<style name="splashscreenTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="android:windowBackground">@drawable/splashscreen</item>
</style>
在清单中:
<application
android:allowBackup="true"
android:icon="@drawable/logo"
android:label="@string/app_name"
android:fullBackupContent="false"
android:theme="@style/AppTheme">
<activity
android:name=".MainActivity"
android:screenOrientation="portrait"
android:label="@string/app_name"
android:theme="@style/splashscreenTheme">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
</application>
</manifest>
【问题讨论】:
-
您在什么设备上看到此行为?
-
您应该使用
Glide库并使用 GlideGlide.with(container.getContext()).load(R.drawable.splashscreen).crossFade().into(imageView);将图像资源加载到您的ImageView中