没有xml定义的ImageView [英] ImageView without xml definition
本文介绍了没有xml定义的ImageView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在Android中创建动态数量的ImageView。
但是为了显示这些ImageView,我必须在main.xml中创建它们(我是否正确?)
有没有办法在main.xml中显示ImageView而不创建它们?
I want to create a dynamic number of ImageViews in Android. But to display these ImageViews I have to create them in the main.xml (Am I right?) Is there a way to display the ImageViews without creating them in the main.xml?
推荐答案
您可以像这样动态创建它们:
You can create them dynamically like this:
ImageView image=new ImageView(this);
并在此动态创建的视图中设置图像使用:
and to set image in this dynamically created view use:
image.setImageResource(R.drawable.yourimage);
这篇关于没有xml定义的ImageView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文