<分区>
如何在 android 上的 Activity 中使用图像而不在 xml 文件中声明它。
我问是因为图像(和实际图像)的数量取决于用户在之前的 Activity 中选择的内容,然后通过 Intent 传递。
我想根据 Intent 中的额外数据创建图像,但在额外数据(数组)上运行 for 循环
<分区>
如何在 android 上的 Activity 中使用图像而不在 xml 文件中声明它。
我问是因为图像(和实际图像)的数量取决于用户在之前的 Activity 中选择的内容,然后通过 Intent 传递。
我想根据 Intent 中的额外数据创建图像,但在额外数据(数组)上运行 for 循环
最佳答案
这是您以编程方式将 ImageView 添加到布局的方式...
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);
问候!
关于android - 如何在不在xml文件android中声明的情况下创建图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17454423/