1

如何在 android 上的活动中拥有图像而不在 xml 文件中声明它。

我问是因为图像(和实际图像)的数量是由用户在上一个活动中选择的内容决定的,然后通过意图传递。

我想根据意图中的额外数据创建图像,但在额外数据(数组)上运行 for 循环

4

1 回答 1

2

这是您以编程方式将 ImageViews 添加到布局的方式...

ImageView imageView = new ImageView(this);
LinearLayout.LayoutParams vp =  new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
imageView.setLayoutParams(vp);        
imageView.setImageResource(R.id.drawableResource);

//You just need to create this layout to hold the images in your XML and get a reference to it...
someLinearLayout.addView(imageView); 

问候!

于 2013-07-03T17:39:27.777 回答