2016-12-01 62 views
0

我有这个应用程序,它使用图像加载器1.9.3库加载图像,并且具有低内存的手机图像加载程序给出的内存异常仅在日志中可见猫。我不介意这个例外,但我希望用户通过敬酒可以看到异常,这样他就知道图像停止加载的原因。 任何想法请内存不足错误图像加载程序

+0

使用滑行。其更多更快避免内存问题.http://www.androidhive.info/2016/04/android-glide-image-library-building-image- gallery-app/ –

+0

缩小图像尺寸 –

+0

guys我不要图像不加载,我只想捕捉图像加载器发出的异常 –

回答

1

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

我建议您使用Picasso

与此你可以根据你的需要调整你的形象。

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

快乐编码。

+0

我个人比较喜欢[Glide](https://github.com/bumptech/glide)毕加索 – EpicPandaForce

+0

以及它完全取决于你。你的任务是调整图像大小。你可以用这两种方法做到这一点。 –

0

也许你的图片是很大,当你下载它们。 800 x 600像素的单张图像在压缩时会小于100kb。但是,当你将它解码成一个位图时,它将变成近似。 2MB的数据。当你加载80本书时,你很快就会得到160MB的数据。 Mabye你应该加载较少的书籍(20)或从服务器减少图像的大小。

通常情况下,logcat将打印一个异常,它会告诉你什么导致OutOfMemoryException。当我得到这个异常时,它一次总是由于太大或太多的图片造成的。

0

尝试添加

android:largeHeap="true" 

在mainfeist文件APP-> SRC->主文件夹

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

要解码文件,你可以使用这个https://stackoverflow.com/a/823966/4741746

的我的解决方案是https://stackoverflow.com/a/13226245/4741746

让我知道如果不沃金

+0

这很有趣,因为'android:largeHeap =“true”'实际上是个好主意。我已经看到小米设备对于已经由Glide调整大小的完全正常图像提出“内存不足错误”。 – EpicPandaForce