2017-06-02 14 views
0

私のアプリには問題があります。outofmemoryerror画像ビューでスクロール表示をスクロールするとき

私の問題は、outofmemoryerrorエラーです。

私は23個の<のアイテムを持っており、スクロール時にアイテムのImageViewの事項のサイズ(テキストアイテム0-xの線でそれのイメージ)、それはImageViewのであるscrollviewをスクロールしたときThiseエラーが発生する私の方法

を説明してみてくださいメモリ使用量が大幅に増加します。しかし、私はそれを防ぐ方法を知らないのですか?

イメージビューにビットマップ(キャンバス)を挿入する私のクラスの一部を貼り付けます。

try { 
     Bitmap b = Bitmap.createBitmap(srk, vsk, Bitmap.Config.ARGB_8888); 

     c = new Canvas(b); 
     imageview.setImageBitmap(b); 

    } catch (IllegalArgumentException e) { 
    } 

    paint = new Paint(); 
    paint.setAntiAlias(true); 
    paint.setStyle(Paint.Style.FILL); 


    for (int i=1;i<(prvy.getNasledujuciitemindex(pacage));i++) { 
     if (prvy.citajItem(pacage,i)!=null) { 

      if (prvy.CiZbalene(pacage, i)) { 
       paint.setColor(Color.argb(255, 130, 130, 130)); 
       c.drawRect(zarovnanieXZACDelLine, zarovnanieYDelLine + (i - 1) * vskconst, zarovnanieXKONDelLine, zarovnanieYDelLine + 2 + (i - 1) * vskconst, paint); 

       c.drawBitmap(cross, zarovnanieXX, (float) (context.getResources().getDimensionPixelSize(R.dimen.KorekciaLine) + (int) (i - 1) * vskconst), paint); 
       paint.setColor(Color.argb(255, 130, 130, 130)); 
       DalsiPrvok(paint, c, prvy.citajItem(pacage, i), vsk2 + (i - 1) * vskconst, sizetext, font); 
      } else { 
       paint.setColor(Color.BLACK); 
       DalsiPrvok(paint, c, prvy.citajItem(pacage, i), vsk2 + (i - 1) * vskconst, sizetext, font); 
      } 
     } else {break;} 

    } 
    imageview.invalidate(); 

このコードのみがimageviewに書き込まれます。

ここは私のXMLです。

  <ScrollView 
         android:id="@+id/scrollView2" 
         android:layout_width="fill_parent" 
         android:layout_height="wrap_content" 
         android:scrollIndicators="none" 
         android:scrollbars="none"> 

         <LinearLayout 
          android:layout_width="match_parent" 
          android:layout_height="wrap_content" 
          android:orientation="vertical"> 

          <FrameLayout 
           android:id="@+id/Pack1" 
           android:layout_width="fill_parent" 
           android:layout_height="fill_parent" 
           android:background="#e1e1e1" 
           android:paddingBottom="@dimen/Pack_Bottom" 
           android:visibility="visible"> 

           <LinearLayout 
            android:id="@+id/linear1" 
            android:layout_width="match_parent" 
            android:layout_height="wrap_content" 
            android:orientation="vertical"> 



            <ImageView 
             android:id="@+id/listPrvy" 
             android:layout_width="match_parent" 
             android:layout_height="0dp" 
             android:clickable="true" 
             android:longClickable="true" 
             android:scaleType="fitXY"/> 
           </LinearLayout> 

          </FrameLayout> 
          </LinearLayout> 
          </ScrollView> 

私は(ImageViewのにビットマップを書き込む)方法↑

itemimg =新しいItemsInPacagesImageView(imglist1、tentocontext、nazovtripu、0、prvy)を呼び出します。 - このクラスは、imglist1(imageview)にビットマップを入れるメソッドです。

私はb.recycle()を試してみます。ビットマップの後にb = Bitmap.createBitmap(srk、vsk、Bitmap.Config.ARGB_8888);

 c = new Canvas(b); 
     imageview.setImageBitmap(b); 

リサイクルされたビットマップを使用するようなアプリケーションがクラッシュしました。

ありがとうございます。それは後にスクロールを開始しています

Image

階段が...(25の項目は、高さ5040pxを1080幅)

答えて

0

ビットマップは、多くのメモリを取ります。いくつかのヒントは次のとおりです。

  1. Bitmap.Config.ARGB_8888を避けてください。不透明な画像の場合は、Bitmap.Config.RGB_565
  2. BitmapFactory.Options.inPurgeable = trueを画像に使用してください。それは最後のAndroidのバージョンでは非推奨ですが、あなたは、画像を扱う起動したときに、Android上で一般的な問題の
+0

私は変化を見ていません。アプリもクラッシュしました。 – trip07

+0

これらの変更はメモリ使用量を減らすだけです。未使用の画像への参照を保持しないでください。同時に多くの画像を保存しないでください。メモリプロファイラも使用してください。 – rupashka

0

一つが来る古いものでは正常に動作しています、それはたくさんのOutOfMemoryErrorが発生の原因となり、高解像度の写真を専門としています。

あなたがイメージによって原因アンドロイド上の任意のOutOfMemoryErrorの問題を避けたい場合は、私はピカソを使用するためにあなたをアドバイス: Link

+0

インターネットや電話のメモリから画像を読み込まない、プログラム実行中に生成しました。 – trip07

関連する問題