Android 动态添加的图像不显示

Android 动态添加的图像不显示,android,image,dynamic,Android,Image,Dynamic,在这段代码中,我构建了一个方法,可以在运行时多次将相同的图像添加到相对布局中。但是,调试时不会显示图像。添加的textview运行正常。有人能解释一下如何使图像可见吗?提前谢谢 我的代码: public class TestActivity extends Activity { ArrayClass arraysObject1 = new ArrayClass(); ArrayList<ImageView> mImages = new ArrayList<ImageView&g

在这段代码中,我构建了一个方法,可以在运行时多次将相同的图像添加到相对布局中。但是,调试时不会显示图像。添加的textview运行正常。有人能解释一下如何使图像可见吗?提前谢谢

我的代码:

public class TestActivity extends Activity {
ArrayClass arraysObject1 = new ArrayClass();
ArrayList<ImageView> mImages = new ArrayList<ImageView>();

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        RelativeLayout layout = new RelativeLayout(this);

        RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.MATCH_PARENT);
        params.addRule(RelativeLayout.ALIGN_PARENT_LEFT, RelativeLayout.TRUE);
        layout.setLayoutParams(params);
        layout.setBackgroundColor(Color.parseColor("#FFFFFF"));

        //textview is working
        TextView testText = new TextView(this);
        testText.setText("Alle aangeboden vacatures vindt u hieronder terug.");
        testText.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
    layout.addView(testText);


        RelativeLayout.LayoutParams imgParams = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
        imgParams.addRule(RelativeLayout.CENTER_IN_PARENT);

        for(int i=0; i<arraysObject1.array1.size(); i++)
        {
            mImages.add(new ImageView(this));
            mImages.get(i).setVisibility(View.VISIBLE);
            mImages.get(i).setBackgroundResource(R.drawable.work);
            mImages.get(i).setLayoutParams(imgParams);

            layout.addView(mImages.get(i));

        }
        setContentView(layout);
    }
}
公共类测试活动扩展活动{
ArrayClass arraysObject1=新的ArrayClass();
ArrayList mImages=新的ArrayList();
创建时的公共void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
RelativeLayout布局=新的RelativeLayout(此);
RelativeLayout.LayoutParams params=新的RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_父级,RelativeLayout.LayoutParams.MATCH_父级);
params.addRule(RelativeLayout.ALIGN_PARENT_LEFT,RelativeLayout.TRUE);
布局。setLayoutParams(参数);
layout.setBackgroundColor(Color.parseColor(#FFFFFF”);
//textview正在工作
TextView testText=新的TextView(此);
setText(“Alle aangeboden Vacations vindt u hieronder terug.”);
setLayoutParams(新的LayoutParams(LayoutParams.FILL_父级,LayoutParams.WRAP_内容));
layout.addView(testText);
RelativeLayout.LayoutParams imgParams=新的RelativeLayout.LayoutParams(LayoutParams.WRAP\u内容,LayoutParams.WRAP\u内容);
imgParams.addRule(父对象中的相对位置中心);
for(int i=0;i您的周期
for(int i=0;i
似乎没有执行。
arraysObject1.array1
是空的。

太多的
imageview
可能会抛出
OutOfMemoryException
。我想:)你是对的!我没有考虑到这种可能性。谢谢。我也经常犯这样的错误:)