在Android Studio中获取随机图像 [英] Get random images in Android Studio

查看:578
本文介绍了在Android Studio中获取随机图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试为Android应用创建纸牌游戏(用于练习),我想知道如何将随机纸牌上传到玩家手中?我已经实现了GUI,我想我需要一些与typedarray和

I am trying to create a card game for an android app (for practice) and I was wondering how would I upload random cards into the players hand? I have the GUI implemented and I think I would need something along the lines of a typedarray and

   ((ImageView)findViewById(R.id.textView18)).setImageResource(R.drawable.1c);

我要沿着这个方向走吗?

Am I moving along the right tracks with this?

推荐答案

您可以像这样获得随机图像:

You can get random images like this:

int[] images = {R.drawable.img1,R.drawable.img2,R.drawable.img3,R.drawable.img4};
Random rand = new Random();
imageView.setImageResource(images[rand.nextInt(images.length)]);

这篇关于在Android Studio中获取随机图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆