Universal Image Loader は、メモリを節約するために縮小された画像をメモリに保持します。すべての縮小画像のサイズが計算され、この画像のターゲット ImageView に依存します ( android:layout_width
、android:layout_height
、android:maxWidth
、android:maxHeight
パラメーター、android:scaleType
、デバイスの画面サイズが考慮されます)。
デフォルトでは、すべての画像の最大ターゲット サイズはデバイスの画面サイズです。そのため、デバイスの画面サイズに似たサイズの画像があり、ズームすると品質が低下します。
そのため、ImageView フルサイズの画像をロードする必要があります (品質を損なうことなくズームをサポートするため)。
メモリにキャッシュされた画像の独自の最大サイズを設定します。
ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(getApplicationContext())
...
.memoryCacheExtraOptions(1200, 1000) // maximum width and height of your images
...
.build();
この場合、大きなビットマップをメモリにロードするので、メモリにキャッシュしないことをお勧めします。.cachenMemory()
これらの画像のメモリ キャッシュを無効にし (DisplayImageOptions で呼び出さないでください)、 を設定し.imageScaleType(ImageScaleType.EXACT)
ます。.defaultDisplayImageOptions(...)
それらをグローバルに ( で)、または表示タスクごとに ( imageLoader.displayImage(...)
)無効にすることができます。
OOM を防止するには:
.cachenMemory()
これらの画像のメモリ キャッシュを無効にします ( DisplayImageOptionsを呼び出さないでください)。
- 設定
.imageScaleType(ImageScaleType.EXACT)
- 設定
.threadPoolSize(1)
(最後の試行として)
アダプタのビットマップをリサイクル:
private class ImagePagerAdapter extends PagerAdapter {
...
@Override
public void destroyItem(View container, int position, Object object) {
View view = (View) object;
((ViewPager) container).removeView(view);
ImageView imageView = (ImageView) view.findViewById(R.id.image);
BitmapDrawable bd = (BitmapDrawable) imageView.getDrawable();
if (bd != null) {
Bitmap bmp = bd.getBitmap();
if (bmp != null) {
bmp.recycle();
}
}
}
...
}