建议我避免 android 中出现内存不足错误的好方法

Suggest me good way to avoid outofmemory error in android

我是 android 的新手,请向我推荐一种优化图像的好方法或一些我用来在我的应用程序中设置图像而不会出现内存不足错误的库...

感谢任何帮助。

感谢任何提前:)

其实要看情况

1).如果您在 Recyclerview、Gridview 等

中显示基于 URL 的图像

您可以根据需要使用图像加载程序库

下面是库link选择你想使用的:

滑行:https://github.com/bumptech/glide

毕加索:https://github.com/square/picasso

通用图片加载器:https://github.com/nostra13/Android-Universal-Image-Load

现在选择哪个我个人推荐glide.if你想要加载大尺寸图片而不是通用图片加载器,如果你想要加载小图片而不是毕加索

2).如果你要在不同的地方使用相同的位图,你可以使用 位图缓存

位图缓存技术

  1. LruCache
  2. 磁盘缓存

3).一些可以帮助您解决 OutOfMemory 错误的设置:

在清单文件中,您可以设置 largeHeap="true"

<application
        android:name=".MyApplication"
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="Mall"
        android:largeHeap="true"
        android:logo="@drawable/logo_for_up"
        android:screenOrientation="portrait"
        android:theme="@style/AppTheme" >
</application>

希望这个答案对你有帮助..如果你需要任何其他帮助,你可以寻求它