2016-03-15 110 views
0

爲了將圖像加載到列表視圖中(在我的情況下爲25 kb「個人檔案」圖片)昨天我綁定了picasso,因此圖像加載速度更快並緩存到磁盤。但從那時起,即使我不打開圖像加載的活動,我也會經常出現內存不足錯誤。 它可能是緩存不清除,所以我的應用程序不能處理任何服務器請求了?有人也會遇到這個問題嗎?或者我基本上做錯了什麼?畢加索內存不足錯誤?

Genreally我的應用程序開始加載谷歌地圖標記放置在由JSON請求給定的特定位置。如果我滑動到另一個地方加載這些標記,嘗試從服務器加載JSON時會發生內存不足錯誤。之前從未發生過,只是因爲我將picasso庫加入了我的應用程序。

,這裏是我的列表視圖列表項:

<?xml version="1.0" encoding="utf-8"?> 
<ListView xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent" android:layout_height="match_parent"> 

<ImageView 
    android:layout_width="40dp" 
    android:layout_height="40dp" 
    android:padding="8dp" 
    android:id="@+id/friends_image" 
    /> 

<TextView xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:minHeight="?android:attr/listPreferredItemHeight" 
    android:layout_toRightOf="@+id/friends_image" 
    android:gravity="center_vertical" 
    android:id="@+id/list_item_friends_textview" /> 

<TextView xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:id="@+id/text_view_id" 
/> 

+0

你的圖片是否有這個屬性? :'android:adjustViewBounds =「true」'也試過'.fit()。centerCrop()' –

+0

是的@rudi,在xml中 –

+0

將它添加到所有的圖像上並測試它,並讓我知道它是否拋出內存 –

回答

0

使用ScaleType

<ImageView 
     android:id="@+id/grid_item_image" 
     android:layout_width="wrap_content" 
     android:paddingLeft="15dp" 
     android:paddingRight="15dp" 
     android:layout_gravity="center" 
     android:scaleType="fitXY" 
     android:layout_height="100dp"/> 
+0

所以我應該這樣做,添加scaleType和android:adjustViewBounds =「true」? – rudi

+0

是的,你不能在網絡上的問題 –

0

添加AndroidManifest.xml文件

<application 
      .... 
      .... 
      android:largeHeap="true" 

</application> 
+0

很多人說這不是解決方案,因爲它從長遠來看並沒有真正解決問題......? – rudi

+0

是的,它不解決問題,而是爲其他正在運行的應用程序的問題,它告訴系統應用程序需要更多的內存,因此係統通過殺死其他後臺應用程序獲取內存 –