应用程序在模拟器上工作但在S8上崩溃

时间:2017-11-15 22:35:00

标签: android xml android-studio memory bitmap

我正在为我的应用的启动画面使用2张图片。我的ImageView(src)中的徽标和布局中的背景(:背景),虽然我的应用程序在模拟器上工作正常但它在我的手机上崩溃(S8)。下面你可以看到我的xml文件负责我的splashScreen和异常。根据我的理解,这些图像中的一个(或两者?)被认为对我的手机内存来说太大了?然而,他们的维度是: 标志(1305x641) 背景(1688x1125)。

有关如何解决此问题的任何想法?我想提供不同分辨率版本的图像,但我在这个过程中迷失了。

export CLOUDSDK_PYTHON=/usr/bin/python

例外:

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/background"
    android:gravity="center_horizontal|center_vertical"
    tools:context="com.spdesigns.funfacts.SplashScreen">


<ImageView
    android:id="@+id/logoImageView"
    android:layout_width="377dp"
    android:layout_height="293dp"
    android:layout_marginBottom="8dp"
    android:layout_marginEnd="8dp"
    android:layout_marginStart="8dp"
    android:layout_marginTop="8dp"
    android:src="@drawable/logo"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent" />
</android.support.constraint.ConstraintLayout>

2 个答案:

答案 0 :(得分:2)

您正在尝试将120 MB图像加载到内存中。 这比任何应该加载的图像大20倍。

它可以在仿真器上正常工作,因为它们可以利用您的计算机内存,并且可能对内存消耗有更宽松的规则。但真正的设备要严格得多。

您应该执行以下操作:
1)进一步缩小图像
2)对您应用中的所有图像运行PNGCrush。它是一个减少图像内存大小而不会降低质量的程序(阅读其文档的具体内容)
3)为hdpi,xhdpi,xxhdpi和xxxhdpi密度提供不同大小的图像。这样系统就会根据屏幕尺寸加载适当的图像。

答案 1 :(得分:0)

我解决了这个问题。

对于遇到相同问题的任何人,只需在mipmap-xxxhdpi文件夹中移动您的位图即可。由于图像太大,因为我将它放在drawables目录中,因此android将其视为mdpi图像。这导致android更加扩展它,从而导致应用程序崩溃并抛出OutOfMemory异常。通过将其放在mipmap-xxxhdpi文件夹中,android只需将其缩小到目标res。

相关问题