'OutOfMemoryError' 在 ViewFlipper 中向 ImageView 添加多个图像时?

'OutOfMemoryError' while adding multiple images to ImageViews inside ViewFlipper?

我有一个包含 6 个 ViewFlippers 的片段,每个 flipper 至少包含 10 个 ImageViews。我试图加载所有图像并将它们放在 ImageViews 中,但受限的内存不允许我这样做。每次我 运行 应用程序都会发生此异常。

当我减少我的应用程序的图像数量 运行 时,但这不是解决方案。
那么最好的方法是什么?

这是我到目前为止尝试过的:

for(int i=0; i<flippers.length; i++) {
    for (int j = 0; j < names.length; j++) {
        int imageResource = getResources().getIdentifier(names[j], "drawable", rootView.getContext().getPackageName());
        ImageView imageView = new ImageView(rootView.getContext());
        imageView.setImageResource(imageResource);
        flippers[i].addView(imageView);
    }
}

26546-26546/com.azad E/AndroidRuntime﹕ FATAL EXCEPTION: main Process: com.azad, PID: 26546 java.lang.OutOfMemoryError

在加载前使用库调整图像大小

您可以使用的一些库是

Picasso

UIL

此库将帮助您缓存图像。当不需要图像时,您可以将其从内存中清除