有没有办法将一些图像放入数组(值)中?

Is there a way to put some images in an array (values)?

我创建了一个 activity,其中包含一个 viewPager 和 5 个具有 5 种不同颜色的片段。每个视图必须有自己的颜色和自己的图片。 对于颜色,我将颜色资源放在一个数组中。每个视图都有一个数字位置,然后数字位置 = 数组位置 = 颜色。工作正常。

但是图片怎么办呢?

是的,您可以将图像放入 drawable 文件夹和 Activity 您可以使用这种方式将图像放入数组中:

int[] images = {R.drawable.imageone,R.drawable.imagetwo,R.drawable.imagethree};

并为 imageview 设置可绘制对象

ImageView mainImage = (ImageView) findViewById(R.id.imageView1);
//set the first image
mainImage.setImageResource(images[0]);