Android - 我在向 RelativeLayout 添加超过 8 个图像视图时遇到问题

Android - I am having problems with adding more than 8 imageviews to RelativeLayout

enter ?

我需要向 RelativeLayout 添加 24 张图像,我首先尝试使用 XML, 在我添加第 8 个 ImageView 后,它刚刚关闭了应用程序。 所以我尝试使用上面的编码,它向我显示了该消息。 它说 OutOfMemory, failed to allocate ___ to a memory with 6mb OOM 我真的不知道这是什么意思,但我猜图像文件太大了? 当我也尝试使用 XML 时,它导致了这样的错误。

enter image description here

不过整组图片都不到100kb。

我该如何处理这个问题?

您的可绘制文件夹中似乎有可绘制对象。所以如果你有真正大密度的屏幕,它会缩放。您应该手动为所有 dpi 或初始图像创建缩放图像:

Options options = new Options();
options.inScaled = false; 
bitmapImage = BitmapFactory.decodeResource(context.getResources(),
                                       R.drawable.imageName, options);
imageview.setImageBitmap(bitmapImage);

InputStream is = this.getResources().openRawResource(imageId);
Bitmap originalBitmap = BitmapFactory.decodeStream(is);  
imageview.setImageBitmap(originalBitmap);

使用 Picssso 库 (http://square.github.io/picasso/)。它有 fit() 方法,对于加载许多图像非常有用。示例:

Picssso.with(context).load(R.drawable.yourimage).fit().into(yourImageView);