【发布时间】:2016-07-15 05:46:13
【问题描述】:
我有一个应用程序,其中有一个恒定的背景图像。我想在单击时随机更改此背景图像。我该怎么做?
【问题讨论】:
标签: android random background
我有一个应用程序,其中有一个恒定的背景图像。我想在单击时随机更改此背景图像。我该怎么做?
【问题讨论】:
标签: android random background
int images[] = {R.drawable.image1, R.drawable.image2, R.drawable.image2};
view.setBackgroundDrawable(getResources.getDrawable(image[new Random().nextInt(images.length())]));
创建一个可绘制的数组 使用图像数组上的可绘制对象设置视图的背景,因此您需要一个随机索引。
【讨论】: