我可以创建使用对于Android的声明中多次ImageViews? [英] Can I create multiple ImageViews using a For statement in Android?

查看:123
本文介绍了我可以创建使用对于Android的声明中多次ImageViews?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个游戏,其中需要在网页上显示ImageViews的数目在不同的层次不同的

I have a game where the number of ImageViews shown on the page need to be different on different levels.

因此​​,第一级可能有4个,第二级可能有6等...

So the first level might have 4, second level might have 6, etc...

我可以用一个For语句编程创建ImageViews?

Can I use a For statement to create the ImageViews programmatically?

如:

for (int i = 0; i < numImages; i++{
   ImageView iv = new ImageView(this);
   .......
}

是否有可能做到这一点?我将如何设置的ImageView变量名是每个ImageView的不同,这样我可以对他们再打?

Is it possible to do this? How would I set the ImageView's variable name to be different for each ImageView so that I can call on them later?

如果这是不可能的,什么是一些其他的设计方案?的ImageViews要在一个正方形/矩形被布置彼此相邻象匹配的中的4组,第6,8,12,14,16,和18个游戏。

If this isn't possible, what are some other design options? The ImageViews are going to be laid out in a square/rectangle next to each other like a game of match in groups of 4, 6, 8, 12, 14, 16, and 18.

感谢您预先的任何帮助!

Thank you in advance for any help!

推荐答案

您可以把它们放入数组:

you can put them in an array:

ImageView[] imageViewArray = new ImageView[numImages];

    for (int i = 0; i < numImages; i++ ) {
        imageViewArray[i] = new ImageView(this);
        imageViewArray[i].setSomething(somethingelse); // unique property for every imageView
    }

这篇关于我可以创建使用对于Android的声明中多次ImageViews?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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