【发布时间】:2020-06-26 04:40:45
【问题描述】:
你好我是一个学习Java的初学者 我正在尝试创建随机图像输出 我制作的代码停止了,只出现了一张图片 我想要的是继续随机显示图像 我应该添加哪个代码? 请帮帮我
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ImageView imageView_1 = findViewById(R.id.imageView_1);
int[] images = {R.drawable.img_1, R.drawable.img_2, R.drawable.img_3, R.drawable.img_4, R.drawable.img_5};
Random rand = new Random();
imageView_1.setImageResource(images[rand.nextInt(images.length)]);
}
}
【问题讨论】:
-
您希望每隔几秒更换一次图像吗?这就是你想要的吗?
-
您需要编写定期更改图像的代码。这可能会有所帮助:stackoverflow.com/questions/6425611/…
-
我想做的是图像每秒随机变化。