内存不足错误图像加载器

Out of Memory Error Image Loader

我有这个应用程序,它使用图像加载器 1.9.3 库从 Web 服务加载图像,并且在手机内存不足的情况下,图像加载器发出内存不足异常,该异常仅在日志猫中可见。我不介意异常,但我希望通过吐司让用户看到异常,以便他知道为什么图像停止加载。 有什么想法请

可能是你下载的图片太大了。一张 800 x 600 像素的图像在压缩后为 JPG 格式时将小于 100kb。但是,当您将其解码为位图时,它将变为大约。 2MB 的数据。当您加载 80 本书时,您将很快获得 160MB 的数据。也许你应该加载更少的书 (20) 或减少来自服务器的图像的大小。

通常,logcat 会打印一个异常,它会告诉您导致 OutOfMemoryException 的原因。当我得到这个异常时,它总是由一次太大或太多图片引起的。

ImageView 的尺寸相比,您的图片太大了。

我推荐你使用Picasso

有了这个,您可以根据需要调整图像的大小。

Picasso.with(this).load(image_link)
    .resize(100, 100)
    .placeholder(R.drawable.placeholder)
    .error(R.drawable.placeholder)
    .into(imageView);

编码愉快。

尝试添加

 android:largeHeap="true"

在您的 mainfeist 文件中 app->Src->Main 文件夹

<application
    android:name="com.xxxxxxxxxxxxxx"
    android:icon="@drawable/app_icon"
    android:label="@string/app_name"

    android:largeHeap="true"

    android:theme="@style/myAppTheme">

    <activity
        android:name="com.xxxxxxxxxxxxxx"
        android:label="@string/app_name"
        android:screenOrientation="portrait"
        android:theme="@style/Theme.AppCompat.Light.NoActionBar">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

要解码文件你可以使用这个

我的解决方案是

如果睡不着请告诉我