2016-12-01 63 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