Android:使用高分辨率绘图设备时会出现极端滞后

Android:使用高分辨率绘图设备时会出现极端滞后,android,android-studio,Android,Android Studio,我决定在我的应用程序开始时创建一个splashscreen。我创建了一个1600x900图像,并将其用作可绘制图像。当我运行我的应用程序时,似乎每个动作都有1秒的延迟。检查完所有东西后,我意识到是飞溅屏幕造成了这种延迟。测试表明,高分辨率图像以这种方式制作成可拉丝,会导致延迟,我不知道为什么 <application android:allowBackup="true" android:icon="@drawable/logo" an

我决定在我的应用程序开始时创建一个splashscreen。我创建了一个1600x900图像,并将其用作可绘制图像。当我运行我的应用程序时,似乎每个动作都有1秒的延迟。检查完所有东西后,我意识到是飞溅屏幕造成了这种延迟。测试表明,高分辨率图像以这种方式制作成可拉丝,会导致延迟,我不知道为什么

    <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>
我的图像重100kb,我逐渐降低了分辨率,尺寸和延迟也逐渐降低。我还制作了一张高分辨率、5kb的图像,延迟持续存在,这意味着分辨率是罪魁祸首

    <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>
为什么会发生这种情况?我怎样才能拥有一个splashscreen而不受后续影响

    <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>
代码:

    <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>
样式:

<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>

@可抽出式/飞溅式挡风玻璃
在舱单中:

    <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>

您遇到的延迟可能是由于垃圾收集或堆大小增加造成的

    <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>
您的图像是
1600*900=1440000px
。每个像素的内存大小为四个字节-每种颜色一个(RGB),透明度一个(A)。因此,我们可以计算:
1440000*4B=5760000B
因此堆上仅为字节数组分配了大约5.7MB。但是它是一个可绘制的,并且比字节数组有更多的字段,因此最终会得到更多的字段

    <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>
添加活动、字符串、其他图像和资源,这会更高

    <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>
现在,每当您创建一个新对象时,VM都会尝试删除一些未使用的对象(垃圾收集),这会导致一个小的延迟。如果无法释放足够的内存,堆将增加(也会导致小的延迟)

    <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>
你可能正面临这些问题之一,那么你能做些什么呢

    <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>
虽然不是你写的,但我认为启动屏幕并不是你应用程序的唯一活动。问题是启动屏幕在后台保持活动状态。您实际上不能对此做任何事情,但至少可以手动删除drawable

    <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>
View window = getWindow().getDecorView();
if (window.getBackground() != null) {
    window.getBackground().setCallback(null);
    window.setBackground(null);
}
一般来说,最好不要在xml属性中使用大型图像。以您真正需要的大小(并非所有设备都有1600*900分辨率)自己创建位图会更节省内存

    <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>

Android为您提供了
BitmapFactory
类来完成此操作。查看并获取有关整个主题的更多信息。

您遇到的延迟可能是由于垃圾收集或堆大小增加造成的

    <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>
您的图像是
1600*900=1440000px
。每个像素的内存大小为四个字节-每种颜色一个(RGB),透明度一个(A)。因此,我们可以计算:
1440000*4B=5760000B
因此堆上仅为字节数组分配了大约5.7MB。但是它是一个可绘制的,并且比字节数组有更多的字段,因此最终会得到更多的字段

    <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>
添加活动、字符串、其他图像和资源,这会更高

    <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>
现在,每当您创建一个新对象时,VM都会尝试删除一些未使用的对象(垃圾收集),这会导致一个小的延迟。如果无法释放足够的内存,堆将增加(也会导致小的延迟)

    <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>
你可能正面临这些问题之一,那么你能做些什么呢

    <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>
虽然不是你写的,但我认为启动屏幕并不是你应用程序的唯一活动。问题是启动屏幕在后台保持活动状态。您实际上不能对此做任何事情,但至少可以手动删除drawable

    <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>
View window = getWindow().getDecorView();
if (window.getBackground() != null) {
    window.getBackground().setCallback(null);
    window.setBackground(null);
}
一般来说,最好不要在xml属性中使用大型图像。以您真正需要的大小(并非所有设备都有1600*900分辨率)自己创建位图会更节省内存

    <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>

Android为您提供了
BitmapFactory
类来完成此操作。查看并获取有关整个主题的更多信息。

您在什么设备上看到这种行为?您应该使用
Glide
库,并使用Glide
ImageView
将图像资源加载到您的
Glide.with(container.getContext()).load(R.drawable.splashscreen).crossFade().into(ImageView)
您在什么设备上看到这种行为?您应该使用
Glide
库,并使用Glide
Glide.with(container.getContext()).load(R.drawable.splashscreen).crossFade()将图像资源加载到
ImageView
虽然我不确定你的大小计算(我的图像是一个压缩的jpg(也许你说的是Android是如何保存它们的?),但将背景设置为null确实可以解决这个问题。多谢各位@约翰兹。是的,压缩并不重要。只是像素而已。ARGB中的一个像素是4字节。你对此无能为力。虽然我不确定你的大小计算(我的图像是一个压缩的jpg(也许你说的是Android如何保存它们?),但将背景设置为null确实可以解决这个问题。多谢各位@约翰兹。是的,压缩并不重要。只是像素而已。ARGB中的一个像素是4字节。你对此无能为力。
    <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>