【问题标题】:Random change of background images in androidandroid中背景图像的随机变化
【发布时间】:2016-07-15 05:46:13
【问题描述】:

我有一个应用程序,其中有一个恒定的背景图像。我想在单击时随机更改此背景图像。我该怎么做?

【问题讨论】:

标签: android random background


【解决方案1】:
int images[] = {R.drawable.image1, R.drawable.image2, R.drawable.image2};
view.setBackgroundDrawable(getResources.getDrawable(image[new Random().nextInt(images.length())]));

创建一个可绘制的数组 使用图像数组上的可绘制对象设置视图的背景,因此您需要一个随机索引。

【讨论】:

    猜你喜欢
    • 2012-06-26
    • 1970-01-01
    • 1970-01-01
    • 2013-01-14
    • 2013-06-21
    • 1970-01-01
    • 2012-02-08
    • 1970-01-01
    • 2010-11-27
    相关资源
    最近更新 更多