私のアプリには問題があります。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);
リサイクルされたビットマップを使用するようなアプリケーションがクラッシュしました。
ありがとうございます。それは後にスクロールを開始しています
階段が...(25の項目は、高さ5040pxを1080幅)
私は変化を見ていません。アプリもクラッシュしました。 – trip07
これらの変更はメモリ使用量を減らすだけです。未使用の画像への参照を保持しないでください。同時に多くの画像を保存しないでください。メモリプロファイラも使用してください。 – rupashka